java程序设计 第2章试题_第1页
java程序设计 第2章试题_第2页
java程序设计 第2章试题_第3页
java程序设计 第2章试题_第4页
java程序设计 第2章试题_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、单项选择题(从下列各题四个备选答案中选出一个正确答案,并将其代号 写在答题纸相应位置处。答案错选或未选者,该题不得分。每小题 1 分,共 10 分。 ) 1、下面哪个是 Java 比较运算符(A) A. = B. := C. = D. =: 2、下面表达式中哪个可以正确的把 1 赋值给变量 X(B) A. 1 = x; B. x = 1; C. x := 1; D. 1 := x; 3、把 MAX_LENGTH 定义为常量,并且赋值为 99.98(B) A. final MAX_LENGTH = 99.98; B. final float MAX_LENGTH = 99.98; C. double MAX_LENGTH = 99.98; D. final double MAX_LENGTH = 99.98; 4、为了提高可读性和可维护性,你应该声明_而不是使用文字的价值, 例如 3.14159 A. variables B. methods C. constants D. classes 5、下面那些数据类型哪个需要的内存量最大(A)? A. long B. int C. short D. byte 6、下面哪个表达式是正确的(C) A. int number = 2L; B. int number = 2l; C. int number = 2; D. int number = 2.0; 7、 表达式 45/4 的结果是(B ) A10 B. 11 C. 11.25 D. 12 8、下面哪个表达式的结果是 1(D) A. 2 % 1 B. 15 % 4 C. 25 % 5 D. 37 % 6 9、分析下面的代码,输出的结果是(D) public class Test public static void main(String args) int month = 09; System.out.println(“month is “ + month); A. month is 09 B. month is 9 C. month is 9.0 D. 程序报错 10、Y 的值是多少(C) public class Test1 public static void main(String args) int x = 1; int y = x = x + 1; System.out.println(“y is “ + y); A. y is 0 B. y is 1 C. y is 2 D. 程序报错 11、i 的值为多少(D) public class Test public static void main(String args) int j = 0; int i = +j + j * 5; System.out.println(“What is i? “ + i); A. 0 B. 1 C. 5 D. 6 12、分析下面代码,i 的值为多少(C) public class Test public static void main(String args) int j = 0; int i = j+ + j * 5; System.out.println(“What is i? “ + i); A. 0 B. 1 C. 5 D. 6 13、下列代码的输出结果是(C) public class Test public static void main(String args) int x = 1; int y = x+ + x; System.out.println(“y is “ + y); A. y is 1. B. y is 2. C. y is 3. D. y is 4. 14、下列代码的输出结果是(B) public class Test public static void main(String args) int x = 1; int y = x + x+; System.out.println(“y is “ + y); A. y is 1. B. y is 2. C. y is 3. D. y is 4. 15、指定一个双变量 d 转换为一个浮点变量 x(D) A. x = (long)d B. x = (int)d; C. x = d; D. x = (float)d; 16、下面代码输出的结果是(D) double x = 5.5; int y = (int)x; System.out.println(“x is “ + x + “ and y is “ + y); A. x is 5 and y is 6 B. x is 6.0 and y is 6.0 C. x is 6 and y is 6 D. x is 5.5 and y is 5 17、表达式(double)5/2 的结果是(B) A. 2; B. 2.5; C. 3; D. 2.0 18、表达式(double)(5/2)的结果是( D) A. 2; B. 2.5; C. 3; D. 2.0; 19、如果您尝试新增一个 int ,一个 byte,一个 long 和一个 double,结果将是 (D)型。 A. byte B. int C. long D. double 20、以下哪项是正确表达的字符 4(D) A. 4 B. “4“ C. 0004 D. 4 21、一个 Java 字符占(D) A. one byte B. two bytes C. three bytes D. four bytes 22、下列语句显示的结果是什么(C) char x=b; System.out.println(+x ) ; A. a B. b C. c D. d 23、下面哪个语句可以正确输入 smithexam1test.txt(B) A. System.out.println(“smithexam1test.txt“); B. System.out.println(“smithexam1test.txt“); C. System.out.println(“smith“exam1“test.txt“); D. System.out.println(“smith“exam1“test.txt“); 24、假设变量 i 是 int 型的,下面哪个语句可以输入 i 的统一码(C) A. System.out.println(i); B. System.out.println(char)i); C. System.out.println(int)i); D. System.out.println(i + “ “); 25、a的统一码是 97,那么c的呢?(C) A. 96 B. 97 C. 98 D. 99 26、语句 System.out.println(z - a)输出什么(A) A. 25 B. 26 C. a D. z 27、下面哪个语句是正确的(A) A. char c = d; B. char c =u0041; C. char c = “d“; D. char c = “100“; 28、 “小于过等于”的比较运算符在 Java 中如何表示(B) A. B. != C. = D. = 30、在 Java 中,true 是一个( A) A.关键字 B.一个布尔值 C.和 1 是等价值的 D.和 0 是等价值的 31、下面哪个布尔表达式的值为 true,当一个数在 1 到 100 之间或为负的时候 (B) A. 1 1) | (x 1) B. Integer.parseInt(s); C. integer.parseInteger(s); D. Integer.parseInteger(s); 44、下面哪个方法是将字符串 s 转换为 double 型(A) A. double.parseDouble(s); B. Double.parsedouble(s); C. double.parseDouble(s); D. Double.parseDouble(s); 45、分析下面代码,正确的是(C) import javax.swing.*; public class ShowErrors public static void main(String args) int i; int j; String s = JOptionPane.showInputDialog(null, “Enter an integer“, “Input“, JOptionPane.QUESTION_MESSAGE); j = Integer.parseInt(s); if (j 3) i = (i + 4); A. The program cannot compile because j is not initialized. B. The program cannot compile because i does not have an initial value when it is used in i = i + 4; C. The program compiles but has a runtime error because i deos not have an initial value when it is used in i = i + 4; D. The program compiles and runs fine. 46、下面语句哪个是返回 a 的 b 次幂 ab(C) A. Math.power(a, b) B. Math.exponent(a, b) C. Math.pow(a, b) D. Math.pow(b, a) 47、表达式(int)(76.0252175 * 100) / 100 的值为(A) A. 76.02 B. 76 C. 76.0252175 D. 76.03 48、语句 System.currentTimeMills()返回的是(D) A.当前时间 B.当前时间的毫秒数 C.从凌晨到当前的毫秒数 D.从 1970 年 1 月 1 日 0 点到现在的毫秒数 49、语句 System.out.printf(“%10s“, 123456)(用* 代替空格)输出的结果是( D) A. 123456* B. 23456* C. 123456* D. *123456 50、语句 System.out.printf(“%3.1e“, 1234.56)的输出结果是(C ) A. 0.1e+04 B. 0.123456e+04 C. 0.123e+04 D. 1.2e+03 二、填空题(每空 2 分,共 20 分) 1只要与变量适合, 数值 就可以赋给整型变量,如果字面量太大 超出变量的存储范围,就会出现 溢出 。 2浮点型直接量默认为是 double 型的。 3在赋值语句中,左边变量的数据类型必须与右边值的 相匹配 。 4char ch = a; System.out.println(+ch); 该语句所显示的结果为 b 。 5当一个整数被转换成一个 char 型数据时,只只用整数的低十六位,其余部 分被 闲置 。 63 + 4 * 4 5 * ( 4 + 3 ) 1 的值为 false 。 7要把字符串转换为 int 型的值,使用 Integer 类中的 parseInt() 方法。 8把 double 数转换为 int 型数时可能 数据丢失 。 9 println 方法显示完字符串后光标 向下一行 ,而 print 方法则在完成 后 向后一格 。 10阅读下面程序 public class Test public static void main(String args) char x = a; char y = c; System.out.println(+y); System.out.println(y+); System.out.println(x y); System.out.println(x - y); 其运算结果依次是: d 、 d 、 false 和 -3 。 11程序错误可以分为: 运行时错误 、 逻辑错误 和 编译错 误 。 12Java 提供了表示 int 、 boolean 、 float, double 和 char 的数据类型,它们称为基本数据类型。 13 final 是 Java 的关键字,表示常量不会改变。 14System.out.printf(“amount is %f %en”,32.32,32.32); 该语句的输出是 32.320000 3.232e+01 15假设 X 为 1,执行下述表达式之后 X 的值是 1 (X1) i=( i=1)+i; Syetem.out.println(i); 上面代码输出的结果是: 2 三、判断题(判断以下论述的正误,认为正确的就在答题相应位置划“T” ,错 误的划“F” ,每小题 1 分,共 10 分) 1. 表达式 var+使变量的值增加 1,并且该表达式的值取 var 增加以后的新值。 ( F ) 2. 当两个类型不同的运算对象进行一元运算时,如果运算对象之一是 double 就将另一个自动转换为 double 型。 ( T ) 3. 该表达式 true | true amount is 32.320000 3.323e+01 b) System.out.printf(“amount is %5.4f %5.4e n”, 32.32, 32.32); amount is 32.3200 3.2320e+01 c) System.out.printf(“%6b n”, (1 2); false d) System.out.printf(“%6s n”, “Java”); Java 11输出布尔型值、字符、十进制整数、浮点数和字符串的格式描述符是什么? %b,%c,%d,%f,%c 12分别找出 byte、short、int、long、float 和 double 中的最大和最小数,其中 哪个数据类型要求的存储空间最小。 Byte 类型最小 13试列举出 Java 中变量、常量、方法和类的命名习惯。 类名采用 Pascal 命名法,其中接口名以 I 开头,变量,方法采用 Camel 命名 法,常量全部大写 14如何把一个数字字符串转换为 double 型值?如何把一个整数字符串转换为 int 型值? 采用 Double 类里的 parseDouble()方法转换,采用 Integer 类里的 parseInt()方法 15如何标记注释行和注释段? 文档注释用/ / 注释行/ 注释段/*/ 16使用常量的好处是什么? 保证不变动的数值安全 17如果强制从 double 型转换为 int 型时,double 型值的小数部分是如何处理 的?类型转换是否是改变被转换变量的值? 舍去,改变 18不同的数值类型值能在一起计算吗?为什么? 只要能进行隐式转换,就能进行计算 19列出布尔运算符的优先级,计算下列表达式。 True | true /line3:int i=0; 4 int k = 100.0; 5 int j = i + 1; 6 7 System.out.println(“ j is “ + j + “ and 8 k is “ + k); 9 10 五、程序设计题(每小题 10 分,共 30 分) 1编写程序,从输入对话框读入 double 型的华氏温度,将其转换为摄氏度并 在消息对话框中显示结果。转化公式如下:摄氏度= (5/9)*(华氏度-32) import javax.swing.*; public static class Temperture public static void main(String args) double fahrenheit=0; double celsius=0; huashi=Double.parseDouble(JOptionPane.showInputDialog(“Please input the Fahrenheit Temperture“); celsius=(5/9.0)*(fahrenheit-32); JOptionPane.showMessageDialog(null, “Celsius temperture“+celsius); 2编写程序读入半径和高,用下列公式计算圆柱和体积: 面积= 半径 *半径 *, 体积= 面积 *高。 import javax.swing.*; public class Volume public static void main(String args) double radius=0; double height=0; double area=0; double volume=0; radius=Double.parseDouble(JOptionPane.showInputDialog(“Please input the radius“); height=Double.parseDouble(JOptionPane.showInputDialog(“Please input the height“); area=radius*radius*Math.PI; volume=area*height; JOptionPane.showMessageDialog(null, “The Area is:“+area+“n“+“The volume is:“+volume); 3编写程序读入英尺数,转换为米数并显示结果。一英尺登录 0.305 米。 import javax.swing.*; public static class Meter public static void main(String args) double meter=0; double inch=0; inch=Double.parseDouble(JOptionPane.showInputDialog(“Please input the inch“); meter=inch*0.305; JOptionPane.showMessageDialog(null, “Meters“+meter); 4编写程序将磅数转换为千克。程序提示用户输入磅数,转换程千克并显示结 果。一磅等于 0.454 千克。 import javax.swing.*; public static class Kilogram public static void main(String args) double kilogram=0; double pound=0; inch=Double.parseDouble(JOptionPane.showInputDialog(“Please input the pound“); kilogram=pound/0.454; JOptionPane.showMessageDialog(null, “Kilogram“+kilogram); 5编写一个程序,读入费用和提成率,计算提成与总费用,例如:如果使用者 键入 10 作为费用,15% 作为提成率,计算结果显示$1.5 作为提成费,$11.5 作 为总费用。 import javax.swing.*; public static class Fee public static void main(String args) double fee=0; double cut=0; double totalFee=0; double cutPercent=0; fee=Double.parseDouble(JOptionPane.showInputDialog(“Please input the fee“); cutPercent=(double)(Double.parseDouble(JOptionPane.showInputDialog(“Pleas e input the cut percent without the percent sign“)/100); cut=fee*cutPercent; totalFee=cut+fee; JOptionPane.showMessageDialog(null, “Cut:“+cut+“n“+“Total Fee:“+totalFee); 6编程程序读入 0 到 1000 间的一个整数,并将其各位数字加起来,例如 932,各位数字之和为 14。 import javax.swing.*; public class Number public static void main(String args) int i=0; int temp=0; i=Integer.parseInt(JOptionPane.showInputDialog(“Please input a number range11000“); while(i!=0) temp+=(i%10); i/=10; JOptionPane.showMessageDialog(null, “total= “+temp); 7编写程序将大写字母转换为小写字母,该字母在源代码中制定。 import javax.swing.*; public class UpperWord public static void main(String args) char i=A; i+=32; JOptionPane.showMessageDialog(null, i); 8编写程序读入一个 ASC码(0 到 128 的整数)并显示它表示的字母。 import javax.swing.*; public class Characrter public static void main(String args) char i; int j=0; j=Integer.parseInt(JOptionPane.showInputDialog(“Please input the number within 0128“); i=(char)j; JOptionPane.showMessageDialog(null, i); 9编写程序输入三角形的三个边,判断是否有效。有效是指两边之和是否大于 第 3 边。例如,如果输入 1,2,1,输出应该为: Can edges 1, 2, and 1 form a

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论