java程序设计基础篇 复习笔记 第二单元
1
原始数据类型(primitive data type) == 基本类型 (fundamental type)
byte short int long float double char boolean
引用类型 reference type
2
System.in System.out
java.util.Scanner
Scanner input = new Scanner (System.in);
nextByte()
nextShort()
nextInt()
nextLong()
nextFloat()
nextDouble()
next()
nextLine()
3
标识符
标识符必须是字母数字下划线和$组成的字符序列,习惯上,$只用在机器自动产生的源代码中
不能以数字开头,
不能是保留字,
不可以是true,false,null,
可以为任意长度
区分大小写
4
定名常量 named constant
final datatype CONSTANTNAME = value;
必须在同一条语句中声明和赋值
5
overflow: int value = 2147483647 + 1; int value2 = -2147483648 - 1;
java不会报关于上溢的警告或错误
underflow: java近似认为是0
6
%: 只有当被除数是负数时,余数是负数
7
数值直接量 literal
整型直接量
long 加L或l
浮点型直接量
double 加D或d
float F或f
科学计数法 e或E 12.3e+2 == 12.3e2
8
long System.currentTimeMillis() 返回格林尼治时间GMT 1,1,1970 0:00(UNIX时间戳)到当前时间的毫秒数
9
简介赋值运算符
10
数值类型转换
拓宽类型 widening a type
缩窄类型 narrowing a type
11
Math.pow(base,times)
12
encoding
encoding scheme
char 16
整型转换成char型发生截断
byte需显式转换
Unicode
Unicode Consortium
supplementary character
\u0000-\uFFFF,必须提供4个16位进制数位
如果没有安装中文字体看不到中文字符
13
Escape character 转义字符
14
不要在nextByte(),nextint()等后面使用nextLine()
15
java文档注释
/**开始 */结尾
二元运算符两边应各加一个空格
16
块的风格:
次行 next-line
行尾 end-of-line
17
java 不能从编译错误检测到除0
调试工具
18
javax.swing.JOptionPane.showInputDialog(null,title,message,ircon);
19
int intValue=Integer.parseInt(intString);
输入的如果不是数值或者点击了Cancel都会出现runtime error
Integer类和Double类都包含在java.lang包中
20
'a'-'c'=-2
显示int值
21
java -cp exercise8e.zip Exercise2_1
22
java.util.Scanner
Keyword:
algorithm
assignment operator
assignment statement
backslash(\)
byte type
casting
char type
constant
data type
debugger
debugging
declaration
decrement operator
double type
encoding
final
float type
floating-point number
expression
identifier
increment operator
incremental developing and testing
indentation
int type
literal
logic error
long type
narrowing
operator
overflow
pseudocode
primitive data type
runtime error
syntax error
supplementary Unicode
short type
underflow
Unicode
UNIX epoch
variable
widening
whitespace
习题
2.1
合法:applet,Applet,$4,apps,x,y,radius
关键字:class,public,int
2.2
double miles=100;
final double KILOMETERS_PER_MILE=1.09
double kilometers=miles*KILOMETERS_PER_MILE;
System.out.println(kilometers);
109
2.3
增加可读性,防止改变常量值,易于维护
final int SIZE=20;
2.4
5
15
50
1
6.5
-4.5
2.5
2
-2
-1
4
0
1
2.6
thursday
2.7
byte -128 - 127 8
short -32768 - 32767 16
int -2147483648 - 2147483647 32
long -9,223,372,036,854,775,808 - 92233720369547758807
float +-(1.4E-45 - 3.4028235E+38) 32
double +-(4.9E-324 - 1.797 693 134 862 315 7E+308)
2.8
6
25.0/4
2.9
从计算机的角度都正确
2.10
4/3.0/(r+34)-9*(a+bc)+(double)(3+d*(2+a))/(a+b*d)
2.11
(double)(m*r*r)
m*Math.pow(r,2);
2.12
(2)(3)
2.13
12.3,12.3e+2,23.4e-2,-334.4,20,39F,40D
2.14
2:public static void
4:int k = 100;
7:and 改为 +
2.15
int currentMinute = (int)(System.currentMillis()%36000000/60000*60)
2.16
可以发生自动转换时可以,但是float和int,long和double运算时则需要显式转换
2.17
发生截断 truncation
改变
2.18
12.5
12
2.19
49
65
66
97
98
(
;
O
U
Z
@
Z
q
r
z
2.20
'1','\u3fFa','\b'
2.21
\\
\"
2.23
char c = 'A';
i = (int)c;//i=67
float f = 1000.34f;
int i = (int)f;//变量重复声明,1000
double d = 1000.34;
int i = (int)d;//1000
int i = 97;
char c = (char)i;//'c'
2.24
'b'
'c'
-2
2.25
11
11
111
12
111
2.26
1Welcome11
1Welcome2
1Welcome2
1Welcomea1
2.27
常量: MAX_VALUE
类或接口: Test
常量或方法名: read,readInt
2.28
.............
2.29
语法错误: 语法不合规范,编译器报错
运行错误: 运行过程中报出的错误,影响程序正常运行
逻辑错误: 编程内容出现错误,指令不能达到应有效果
2.30
JOptionPane 是 javax.swing包里的,不是默认导入的
Math类则是java.lang包内的,默认导入
2.31
int i = Integer.parseInt(javax.swing.JOptionPane.showInputDialog(null,"请输入一个整数"));
编程练习:
2.9
public class Exercise2-9 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String money = javax.swing.JOptionPane.showInputDialog(null,"请输入钱数");
int ind=money.indexOf('.');
String penny = money.substring(ind+1);
money=money.substring(0, ind);
int i=Integer.parseUnsignedInt(money,10)*100+Integer.parseUnsignedInt(penny);
javax.swing.JOptionPane.showMessageDialog(null,"answer"+i+"penny","result",JOptionPane.INFORMATION_MESSAGE);
}
}
2.18
public class Exercise {
public static void print(String a){
System.out.printf("%-10s",a);
}
public static void main(String[] args){
print("a");print("b");print("pow(a,b)");System.out.println();
for(int i=1;i<6;i++){
String s = ""+i;
print(s);
s = String.valueOf(i+1);
print(s);
s = ""+(int)Math.pow(i, i+1);
print(s);System.out.println();
}
}
}
2.25
import java.util.Scanner;
public class Exercise {
public static void main(String[] args){
System.out.print("Enter the time zone offset to GMT:");
Scanner scanner = new Scanner(System.in);
int i=scanner.nextInt();
long second=System.currentTimeMillis()/1000-3600*i;
int sec = (int)(second%60);
second/=60;
int min = (int)second%60;
second/=60;
int hour = (int)second%24;
System.out.print("The current time is "+hour+":"+min+":"+sec);
}
}
java程序设计基础篇 复习笔记 第二单元的更多相关文章
- java程序设计基础篇 复习笔记 第一单元
java语言程序设计基础篇笔记1. 几种有名的语言COBOL:商业应用FORTRAN:数学运算BASIC:易学易用Visual Basic,Delphi:图形用户界面C:汇编语言的强大功能和易学性,可 ...
- java程序设计基础篇 复习笔记 第七单元&&第八单元
7.1 int[][] triArray{ {1}, {1,2}, {1,2,3}, }; 7.2 array[2].length 8.1 Unified Modeling Language:UML ...
- java程序设计基础篇 复习笔记 第六单元
第六章 一维数组 1 数组初始化语法 array initializer 2 for each loop 3 off-by-one error 通常是在循环中该使用<的地方使用了<= 4 ...
- java程序设计基础篇 复习笔记 第五单元
1. method header: modifier, return value type, method signature(method name, parameter) method body ...
- java程序设计基础篇 复习笔记 第三单元
1 单向if语句 双向if语句 dangling else switch:char,byte,short,int 2 javax.swing.JOptionPane.showConfirmDialog ...
- java程序设计基础篇 复习笔记 第四单元
1 think before coding code incrementally 2 sentinel value sentinel-controlled loop 3 输入输出重定向 > &l ...
- Java程序设计基础作业目录(作业笔记)
持续更新中............. Java程序设计基础笔记 • [目录] 我的大学笔记>>> 第1章 初识Java>>> 1.1.4 学生成绩等级流程图练习 1 ...
- Java程序设计基础笔记 • 【目录】
持续更新中- 我的大学笔记>>> 章节 内容 实践练习 Java程序设计基础作业目录(作业笔记) 第1章 Java程序设计基础笔记 • [第1章 初识Java] 第2章 Java程序 ...
- 20145322第九周JAVA程序设计基础学习总结
20145322第九周JAVA程序设计基础学习总结 JDBC简介 JDBC全名Java DataBase Connectivity,是java联机数据库的标准规范.它定义一组标准类与接口,应用程序需要 ...
随机推荐
- 2017浙江省赛 H - Binary Tree Restoring ZOJ - 3965
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3965 题目: iven two depth-first-search ...
- android studio 模拟器中文乱码
这是因为编码格式不统一导致的,在android studio的build.gradle加入默认编码声明就可以了 compileOptions.encoding = "GBK" 参考
- java内存回收
java中引用类型 强引用 Persnon p = new Person(); 当指向Person对象的引用计数为0时,Person对象才能被垃圾回收器回收. 软引用 SoftReference&l ...
- 在Linux下不重启让配置文件修改后立即生效的办法
在linux修改配置文件后可能没有生效,比如JDK文件配置,配置后可能没有生效,为了让文件生效,如下操作可以让配置文件生效. 例如,我刚修改了“/etc/profile”或“~/.bash_profi ...
- CentOS6.5安装Qt4.8.6+QtCreator2.6.1
工作中需要用到Qt在Linux下做开发,公司提供的电脑安装的CentOS6.2,但是为了和windows下自己使用的QT版本一直,于是也选择安装了Qt5.1.0.但是在CentOS下刚开始是无法启动, ...
- 用C#连接SFTP服务器并进行上传下载文件
1.使用软件连接可采用WinSCP进行: 文件协议选择SFTP,端口号默认22 2.使用C#代码操作 参考:http://www.cnblogs.com/binw/p/4065642.html 主要引 ...
- WCF基本知识
1.开通WCF调试服务: 须在服务端的行为中作如下配置:includeExceptionDetailInFaults="true" 代码如下: <behaviors> ...
- Linux ASLR的实现
ASLR大家都会听说过,但是Linux平台下应用程序的ASLR的情况是怎么样的呢?我在这里将ASLR分为几个小的部分来阐述,包括了栈的随机化,堆的随机化,mmap的随机化,以及pie程序运行时的主模块 ...
- RN中有两种方式使用全局变量
1.通过导入导出文件的方式 新建constants.js文件 const object = { website:'http://www.hao123.com', name:'好123', }; exp ...
- Linux服务器上ftp的搭建和使用
知识点: 1. FTP的简介.工作原理 2.在Linux上搭建FTP服务器 参考: 阿里云文档:https://help.aliyun.com/knowledge_detail/60152.html ...