1)Suppose a Scanner object is created as follows:

Scanner input = new Scanner(System.in);

What method do you use to read an int value?
A) input.nextInteger(); B) input.integer(); C) input.nextInt(); D) input.int();

2)The following code fragment reads in two numbers: (Choose all that apply.)

Scanner input = new Scanner(System.in);
int i = input.nextInt();
double d = input.nextDouble();

What are the correct ways to enter these two numbers?
A) Enter an integer, a space, a double value, and then the Enter key.
B) Enter an integer, an Enter key, a double value, and then the Enter key.
C) Enter an integer, two spaces, a double value, and then the Enter key.
D) Enter a numeric value with a decimal point, a space, an integer, and then the Enter key.

3)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("Enter three numbers: ");
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);
}
}

A)1.0 B) 2.0 C) 4.0 D) 3.0

4)Every letter in a Java keyword is in lowercase.
A)true B) false

5)Which of the following is a valid(合法的,有效的) identifier? (Choose all that apply.)
A)$343 B)radius C)9X D)8+9 E)class

6)Which of the following are correct names for variables according to Java naming conventions? (Choose all that apply.)
A)RADIUS B)radius C)FindArea D)Radius E)findArea

  • It should start with a lowercase letter such as id, name.
  • It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore).
  • If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName, lastName.
  • Avoid using one-character variables such as x, y, z.

7)Which of the following are correct ways to declare variables? (Choose all that apply.)
A)int length; int width; B) int length, int width;
C)int length; width; D) int length, width;

8)________ is the Java assignment operator.
A)== B) = C) := D) =:

9)To assign a value 1 to variable x, you write _______
A)1 = x; B)x = 1; C)1 := x; D)x == 1; E)x := 1;

10)Which of the following assignment statements is incorrect? (Choose all that apply.)
A)i == j == k == 1; B) i = j = k = 1; C)i = 1; j = 1; k = 1; D) i = 1 = j = 1 = k = 1;

11)To declare a constant MAX_LENGTH inside a method with value 99.98, you write ______
A)final float MAX_LENGTH = 99.98; B)double MAX_LENGTH = 99.98;
C)final double MAX_LENGTH = 99.98; D)final MAX_LENGTH = 99.98;

12)Which of the following is a constant, according to Java naming conventions? (Choose all that apply.)
A)MAX_VALUE B)COUNT C)Test D)ReadInt E)read

13)To improve readability and maintainability, you should declare ________ instead of using literal values such as 3.14159.
A)constants B) methods C)classes D) variables

14)Which of these data types requires the most amount of memory?
A)long B) int C) byte D) short

15)To declare an int variable number with initial value 2, you write ______
A)int number = 2; B) int number = 2.0; C)int number = 2L; D) int number = 2l;

16)What is the result of 45 / 4?
A)11 B) 10 C) 11.25 D) 12

17)Which of the following expressions will yield 0.5? (Choose all that apply.)
A)(double) (1 / 2) B)1 / 2 C)1.0 / 2 D)1 / 2.0 E)(double) 1 / 2

18)Which of the following expression results in a value 1?
A)15 % 4 B) 2 % 1 C) 25 % 5 D) 37 % 6

19)25 % 1 is ________.
A)1 B) 2 C) 3 D) 4 E) 0

20)-25 % 5 is ________.
A)1 B) 2 C) 3 D) 4 E) 0

21)24 % 5 is ________.
A)1 B) 2 C) 3 D) 4 E) 0

22)-24 % 5 is ________
A)-1 B) -2 C) -3 D) -4 E) 0

23)-24 % -5 is ________.
A)3 B) -3 C) 4 D) -4 E) 0

24)To add a value 1 to variable x, you write (Choose all that apply.)
A)x = x + 1; B)x := 1; C)1 + x = x; D)x += 1; E)x = 1 + x;

25)To add number to sum, you write (Note: Java is case-sensitive) (Choose all that apply.)

A)number = sum + number; B)sum += number;
C)number += sum; D)sum = sum + number; E)sum = Number + sum;

26)Suppose x is 1. What is x after x += 2?
A)0 B) 1 C) 2 D) 3 E) 4

27)Suppose x is 1. What is x after x -= 1?
A)0 B) 1 C) 2 D) -1 E) -2

28)What is x after the following statements?
int x = 1;
int y = 2;
x *= y + 1;
A)x is 2. B) x is 3. C) x is 4. D) x is 1.

29)What is x after the following statements?
int x = 1;
x *= x + 1;
A)x is 2. B) x is 3. C) x is 1. D) x is 4.

30)Math.pow(2, 3) returns ________.
A) 9.0 B) 9 C) 8.0 D) 8

31)The ________ method returns a raised to the power of b.
A)Math.exponent(a, b) B) Math.pow(b, a) C)Math.pow(a, b) D) Math.power(a, b)

32)Analyze the following code.

public class Test {
public static void main(String[ ] args) {
int month = 09;
System.out.println("month is " + month);
}
}

A)The program displays month is 9
B)The program displays month is 9.0
C)The program displays month is 09
D)The program has a syntax error, because 09 is an incorrect literal value.

33)What is y displayed in the following code?

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 1 because x is assigned to y first.
B)y is 2 because x + 1 is assigned to x and then x is assigned to y.
C)y is 0.
D)The program has a compile error since x is redeclared in the statement int y = x = x + 1.

34)What is i printed?

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) 6 D) 5

35)What is i printed in the following code?

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)5 B) 6 C) 1 D) 0

36)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 is " + y);
}
}

A)y is 4. B) y is 2. C) y is 3. D) y is 1.

37)What is y displayed?

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 4. D) y is 3.

38)To assign a double variable d to a float variable x, you write _____
A)x = (float)d; B) x = (int)d; C)x = (long)d D) x = d;

39)What is the printout of the following code:
double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);
A)x is 5.5 and y is 5.0
B)x is 6.0 and y is 6.0
C)x is 5.5 and y is 5
D)x is 5 and y is 6
E)x is 6 and y is 6

40)Which of the following assignment statements is illegal? (Choose all that apply.)
A)float f = -34;
B)int t = (int)false;
C)short s = 10;
D)int t = 4.5;
E)int t = 23;

41)What is the value of (double)5/2?
A)2.5 B) 3 C) 3.0 D) 2.0 E) 2

42)What is the value of (double)(5/2)?
A)3 B) 2.0 C) 2.5 D) 2 E) 3.0

43)The expression (int)(76.0252175 * 100) / 100 evaluates to ________.
A)76 B) 76.02 C)76.03 D) 76.0252175

44)If you attempt to add an int, a byte, a long, and a double, the result will be a ________ value.

A)int B) byte C) double D) long

45)Which of the following is the correct expression of character 4?
A)'4' B) "4" C) 4 D) '\0004'

46)A Java character is stored in ________.
A)three bytes B) two bytes
C)one byte D) four bytes

JAVA中,char占2字节,16位,可在存放汉字。

47)Suppose x is a char variable with a value 'b'. What is the printout of the statement System.out.println(++x)?
A)b B) d C) c D) a

48)Which of the following statement prints smith\exam1\test.txt?
A)System.out.println("smith\exam1\test.txt");
B)System.out.println("smith\\exam1\\test.txt");
C)System.out.println("smith"\exam1"\test.txt");
D)System.out.println("smith\"exam1\"test.txt");

对\进行转义

49)Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?
A)System.out.println(i); B) System.out.println(i + " ");
C)System.out.println((char)i); D) System.out.println((int)i);

50)The Unicode of 'a' is 97. What is the Unicode for 'c'?
A)96 B) 99 C) 97 D) 98

51)Will System.out.println((char)4) display 4?
A)Yes B) No

52)What is the printout of System.out.println('z' - 'a')?
A)25 B) z C) a D) 26

53)An int variable can hold ________. (Choose all that apply.)
A)120.0 B) 120 C) "120" D) "x" E) 'x'

int型来存放整型和字符类型

54)Which of the following assignment statements is correct? (Choose all that apply.)
A)char c = "100"; B) char c = 'd'; C)char c = 100; D) char c = "d";

55)The expression "Java " + 1 + 2 + 3 evaluates to ________.
A)Java123 B)Java 123 C)java 123 D)Java6 E)Illegal expression

56)Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.

A)B B) A1 C)66 D) Illegal expression

57)Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.

A)A1 B) 66 C)B D) Illegal expression

int的优先级高于char,向上类型转换

58)The System.currentTimeMillis() returns ________.
A)the current time in milliseconds
B)the current time in milliseconds since midnight, January 1, 1970
C)the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
D)the current time in milliseconds since midnight
E)the current time

59)Programming style is important, because ________. (Choose all that apply.)
A)good programming style can make a program run faster
B)a program may not compile if it has a bad style
C)good programming style helps reduce programming errors
D)good programming style makes a program more readable

60)According to Java naming convention, which of the following names can be variables? (Choose all that apply.)
A)TOTAL_LENGTH B)totalLength C)class D)findArea E)FindArea

61)If a program compiles fine, but it produces incorrect result, then the program suffers ________.
A)a logic error B)a compilation error C)a runtime error

63)The ________ method parses a string s to an int value.
A)integer.parseInt(s); B)Integer.parseInteger(s); C)integer.parseInteger(s); D) Integer.parseInt(s);

64)The ________ method parses a string s to a double value.
A)Double.parsedouble(s); B) double.parse(s);
C)double.parseDouble(s); D) Double.parseDouble(s);

65)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, "Enter an integer", "Input", JOptionPane.QUESTION_MESSAGE);
j = Integer.parseInt(s);
i = (i + 4);
}
}

A)The program compiles but has a runtime error because i does not have an initial value when it is used in i = i + 4;
B)The program compiles and runs fine.
C)The program cannot compile because i does not have an initial value when it is used in i = i + 4;
D)The program cannot compile because j is not initialized.

 Java未初始化的局部变量不能直接使用

Java题库——Chapter2 基础程序设计的更多相关文章

  1. Java题库——Chapter14 JavaFX基础

    Chapter 14 JavaFX Basics Section 14.2 JavaFX vs Swing and AWT1. Why is JavaFX preferred?a. JavaFX is ...

  2. Java题库——Chapter13抽象类和接口

    )What is the output of running class Test? public class Test { public static void main(String[ ] arg ...

  3. Java题库——Chapter8 对象和类

    1)________ represents an entity(实体) in the real world that can be distinctly identified. 1) _______ ...

  4. JAVA题库01

    说出一些常用的类,包,接口,请各举5个 常用的类:BufferedReader  BufferedWriter  FileReader  FileWirter  String Integer java ...

  5. Java题库——Chapter17 二进制I/0

    Introduction to Java Programming 的最后一章,完结撒花!Chapter 17 Binary I/O Section 17.2 How is I/O Handled in ...

  6. Java题库——Chapter16 JavaFX UI组件和多媒体

    Chapter 16 JavaFX UI Controls and Multimedia Section 16.2 Labeled and Label1. To create a label with ...

  7. Java题库——Chapter12 异常处理和文本IO

    异常处理 1)What is displayed on the console when running the following program? class Test { public stat ...

  8. Java题库——Chapter11 继承和多态

    1)Analyze the following code: public class Test { public static void main(String[ ] args) { B b = ne ...

  9. Java题库——Chapter10 面向对象思考

    1)You can declare two variables with the same name in ________. 1) _______ A)a method one as a forma ...

随机推荐

  1. Ansible配置批量推送公钥到被管理端

    01.yum安装ansible(推荐) sudo yum install ansible 02.配置被管理端主机IP清单 [root@ansible_50 ansible]$ cp /etc/ansi ...

  2. ubifs开销测试

    问题 在板子上观察到56M的ubi卷,挂载上ubifs之后,df -h显示可用空间约为50M. 如此计算开销超过了10%,那么这个开销随容量如何变化呢,是固定为10%吗还是有其他规律? 理论计算 简单 ...

  3. Day01-基础数据类型/用户交互/流程控制之-if

    1.基础数据类型 什么是数据类型 我们人类可以很容易的分清数字与字符的区别,但是计算机并不能,计算机虽然很强大,但从某种角度上看又很傻,除非你明确的告诉它,1是数字,“汉”是文字,否则它是分不清1和‘ ...

  4. python连接sqlserver和MySQL实现增删改查

    参考python核心编程 编写一个用户洗牌的脚本,根据用户输入,选择连接sqlserver或者MySQL,创建数据库.表,随机生成数据,并实现增删改查. 其中,为了兼容python2和python3, ...

  5. python 多线程编程之进程和线程基础概念

    多线程编程 在多线程(multithreaded,MT)出现之前,计算机程序的执行都是由单个步骤序列组成的,该序列组合在主机的CPU中按照同步顺序执行.无论是任务本身需要按照步骤顺序执行,还是整个过程 ...

  6. Sql将一列数据拆分为多行显示的两种方法

    原始数据与期望结果有表tb, 如下:id          value----------- -----------1           aa,bb2           aaa,bbb,ccc欲按 ...

  7. C#程序编写高质量代码改善的157个建议【16-19】[动态数组、循环遍历、对象集合初始化]

    前言   软件开发过程中,不可避免会用到集合,C#中的集合表现为数组和若干集合类.不管是数组还是集合类,它们都有各自的优缺点.如何使用好集合是我们在开发过程中必须掌握的技巧.不要小看这些技巧,一旦在开 ...

  8. 如何从Mac删除恶意广告软件,摆脱那些通过弹出广告或工具栏入侵Mac的恶意软件

    厌倦了那些利用弹出式广告和工具栏之类入侵Mac的恶意软件?该如何摆脱Mac上的恶意软件呢?今天小编为大家带来两种方法从Mac 删除广告软件,甚至阻止它到达您的Mac,感兴趣的朋友一起来看看吧! 方法一 ...

  9. 【30天自制操作系统】day03:读写磁盘

    软盘 80个柱面,2个磁头,18个扇区 每个扇区 512 字节,共 1440 KB 读磁盘汇编 读取 10 个柱面到 0x0820 内存位置 ;读取磁盘 MOV AX,0x0820 MOV ES,AX ...

  10. threejs 绘制辅助网格

    GridHelper.js可以帮助绘制一个xz平面网格,它没有提供更多的参数,所以不能用于生成xy网格. xy网格实现代码如下: var size = 6000; var divisions = 50 ...