教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 实用模板 >

Java练习题1(有答案)(2)

来源:网络收集 时间:2026-01-29
导读: 第 26题 Suppose x is 1. What is x after x -= 1? 1、 0 2、 1 3、 2 4、 -1 5、 -2 答案 1 第 27题 What is x after the following statements? int x = 1; int y = 2; x *= y + 1; 1、 x is 1; 2、 x is 2; 3、

第 26题 Suppose x is 1. What is x after x -= 1? 1、 0 2、 1 3、 2

4、 -1 5、 -2 答案 1 第 27题 What is x after the following statements? int x = 1; int y = 2; x *= y + 1; 1、 x is 1; 2、 x is 2;

3、 x is 3; 4、 x is 4; 答案 3 第 28题 What is y displayed?

public class Test { public static void main(String[] args) { int x = 1; int y = x + x++; System.out.println(\+ y); } }

1、 y is 1. 2、 y is 2. 3、 y is 3.

4、 y is 4. 答案 2 第 29题 What is y displayed in the following code?

public class Test { public static void main(String[] args) { int x = 1; int y = x++ + x; System.out.println(\+ y); } }

1、 y is 1. 2、 y is 2.

3、 y is 3. 4、 y is 4. 答案 3 第 30题 What is the printout of the following code: double x = 5.5; int y = (int)x;

System.out.println(\ 1、 x is 5 and y is 6 2、 x is 6.0 and y is 6.0 3、 x is 6 and y is 6

4、 x is 5.5 and y is 5 5、 x is 5.5 and y is 5.0 答案 4 第 31题 Suppose x is a char variable with a value b . What is the printout of the statement System.out.println(++x)? 1、 a 2、 b

3、 c 4、 d 答案 3 第 32题 Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?

1、 System.out.println(i); 2、 System.out.println((char)i);

3、 System.out.println((int)i); 4、 System.out.println(i + \答案 2 第 33题 The following code fragment reads in two numbers: Scanner input = new Scanner(System.in); int i = input.nextInt(); double d = input.nextDouble(); What are the correct ways to enter these two numbers?

1、 Enter an integer, a space, a double value, and then the Enter key. 2、 Enter an integer, two spaces, a double value, and then the Enter key. 3、 Enter an integer, an Enter key, a double value, and then the Enter key. 4、 Enter a numeric value with a decimal point, a space, an integer, and then the Enter key. 答案 1 2 3 第 34题 If you enter 1 2 3, when you run this program, what will be the output? import

java.util.Scanner;

public class Test1 {

public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(\double number1 = input.nextDouble(); double number2 = input.nextDouble(); double number3 = input.nextDouble();

// Compute average double average = (number1 + number2 + number3) / 3; // Display result System.out.println(average); }

} 1、 1.0 2、 2.0 3、 3.0

4、 4.0 答案 2 第 35题 The expression (int)(76.0252175 * 100) / 100 evaluates to _________. 1、 76.02 2、 76

3、 76.0252175 4、 76.03 答案 2 第 36题 According to Java naming convention, which of the following names can be variables? 1、 FindArea 2、 findArea 3、 totalLength 4、 TOTAL_LENGTH

5、 class 答案 2 3 第 37题 The __________ method displays an input dialog for reading a string.

1、 String string = JOptionPane.showMessageDialog(null, \ \

2、 String string = JOptionPane.showInputDialog(null, \ \

3、 String string = JOptionPane.showInputDialog(\Demo\

4、 String string = JOptionPane.showInputDialog(null, \ 5、 String string = JOptionPane.showInputDialog(\a string\答案 2 4 5 第 38题 Analyze the following code. import javax.swing.*; public class ShowErrors { public static void main(String[] args) { int i; int j;

String s = JOptionPane.showInputDialog(null, \ JOptionPane.QUESTION_MESSAGE); j = Integer.parseInt(s);

i = (i + 4); } }

1、 The program cannot compile because j is not initialized.

2、 The program cannot compile because i does not have an initial value when it is used in i = i + 4;

3、 The program compiles but has a runtime error because i does not have an initial value when it is used in i = i + 4; 4、 The program compiles and runs fine. 答案 2 第 39题 Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)? 1、 9

2、 10 3、 11 答案 2 第 40题 Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++ > 10). 1、 9

2、 10 3、 11 答案 2 第 41题 Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement? (Please indent the statement correctly first.) if (x > 0) if (y > 0) System.out.println(\> 0 and y > 0\else if (z > 0)

System.out.println(\ 1、 x > 0 and y > 0; 2、 x < 0 and z > 0; 3、 x < 0 and z < 0; 4、 no printout.

答案 2 第 42题 Analyze the following code. boolean even = false; if (even) {

System.out.println(\ }

1、 The code displays It is even! 2、 The code displays nothing.

3、 The code is wrong. You should replace if (even) with if (even == true) 4、 The code is wrong. You should replace if (even) with if (even = true) 答案 2 …… 此处隐藏:2321字,全部文档内容请下载后查看。喜欢就下载吧 ……

Java练习题1(有答案)(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/521351.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)