数据类型和运算符作业
一、 填空题
二、 选择题
1. |
在Java中,以下错误的变量名是( D )。(选择一项) |
|
|
|
|
|
A |
constant |
|
B. |
flag |
|
C. |
a_b |
|
D. |
final |
2. |
以下选项中属于合法的Java标识符的是( CD )。(选择两项) |
|
|
|
|
|
A. |
public |
|
B. |
3num |
|
C. |
name |
|
D. |
_age |
3. |
在Java中,byte数据类型的取值范围是( A )。(选择一项) |
|
|
|
|
|
A |
-128 ~ 127 |
|
B. |
-228 ~128 |
|
C. |
-255 ~ 256 |
|
D. |
-255 ~ 255 |
4. |
下面的代码段中,执行之后i和j的值是( C )。(选择一项) |
|
|
int i=1; int j; j=i++; |
|
|
|
|
|
A |
1,1 |
|
B. |
1,2 |
|
C. |
2,1 |
|
D. |
2,2 |
5. |
下面Java代码的执行结果是( A )。(选择一项) |
|
|
public class Test { public static void main(String args[]) { System.out.println(100 % 3); System.out.println(100%3.0); } } |
|
|
|
|
|
A |
1 1.0 |
|
B. |
1 1 |
|
C. |
1.0 1.0 |
|
D. |
33 33.3 |
6. |
下面的赋值语句中错误的是( A )。(选择一项) |
|
|
|
|
|
A |
float f = 11.1; |
|
B. |
double d = 5.3E12; |
|
C. |
double d = 3.14159; |
|
D. |
double d = 3.14D; |
7. |
在Java中,下面( AB )语句能正确通过编译。(选择两项) |
|
|
|
|
|
A |
System.out.println(1+1); |
|
B. |
char i =2+‘2‘; System.out.println(i); |
|
C. |
String s="on"+‘one‘; |
|
D. |
int b=255.0; |
8. |
有以下方法的定义,请选择该方法的返回类型( D )。(选择一项) |
|
|
method(byte x, double y) { return (short)x/y*2; } |
|
|
|
|
|
A |
byte |
|
B. |
short |
|
C. |
int |
|
D. |
double |
9. |
关于以下Java程序中错误行的说明正确的是( B )。(选择一项) |
|
|
public class Test2 { public static void main(String[] args) { short s1=1; //1 s1=s1+1; //2 s1+=1; //3 System.out.println(s1); } } |
|
|
|
|
|
A |
1行错误 |
|
B. |
2行错误 |
|
C. |
3行错误 |
|
D. |
1行,2行,3行都错误 |
三、 判断题
四、 简答题
基本数据类型:整数型,小数型,字符型,布尔型
2.
单独使用:
放在操作数的前面和后面效果一样。(这种用法是我们比较常见的)
参与运算使用:
放在操作数的后面,先取值参与运算,再自增或者自减。
放在操作数的前面,先自增或者自减,然后再将结果参与运算。
3.
最终结果一样。
具有短路效果。左边是true,右边不执行。
4.
(1)布尔型和其它基本数据类型之间不能相互转换;
(2)byte型可以转换为short、int、、long、float和double;
(3)short可转换为int、long、float和double;
(4)char可转换为int、long、float和double;
(5)int可转换为long、float和double;
(6)long可转换为float和double;
(7)float可转换为double;
五、 编码题
public class TestPerson {
public static void main(String[] args) {
System.out.println("Please input your name here:");
System.out.println("小明");
System.out.println("Please input your age here:");
System.out.println("23");
System.out.println("Please input your gender here:");
System.out.println("男");
System.out.println("The computer recorded that :");
System.out.println("Your name is:小明");
System.out.println("Your age is:23");
System.out.println("Your gender is:男");
}
}
public class TestCircle {
public static void main(String[] args) {
double b=12.5d;
double PI=3.14d;
double c=2*3.14*12.5;
double s=3.14*12.5*12.5;
System.out.println("请输入圆的半径:");
System.out.println(b);
System.out.println("该圆的半径:R="+b);
System.out.println("该圆的周长:C="+ 2 + "*" + PI+ "*" +b+ "=" +c);
System.out.println("该圆的面积:S=" + PI+ "*" +b+ "*" +b+ "=" +s);
}
}
结果如下图所示。(结果四舍五入,不保留小数位。使用Math.round(double d)实现)
public class TestDeposit {
public static void main(String[] args) {
int i=10000;
System.out.println("本金:"+i);
double d1=i*(1+0.35/100);
System.out.println("活期1年本金总计:"+Math.round(d1));
double d2=i*(1+1.50/100);
System.out.println("定期1年本金总计:"+Math.round(d2));
double d3=i*(1+0.35/100*2);
System.out.println("活期2年本金总计:"+Math.round(d3));
double d4=i*(1+2.10/100*2);
System.out.println("定期2年本金总计:"+Math.round(d4));
}
}
六、 可选题
1) ASCII、ISO8859-1、GBK、UNICODE、ANSI等字符集的特点
2) 常用进制(二进制、八进制、十六进制、十进制)的特点及其转换
3) 源码、反码、补码含义、作用及其转换
任意进制--->十进制的转换
十进制 ----->任意进制的转换
原文:https://www.cnblogs.com/wty1994/p/9267746.html