JAVA题库——基础练习1

这是一个包含23道单选题的JAVA基础练习题库,涵盖了变量赋值、比较运算符、循环、条件语句、数据类型转换等方面的知识点,旨在帮助学习者巩固JAVA编程基础。
摘要由CSDN通过智能技术生成

目录

一、单选题

1. (单选题)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);}}

2. (单选题)Suppose x is 1. What is x after x -= 1?

3. (单选题)Which of the following is incorrect?

4. (单选题)What is the value of (double)(5/2)?

5. (单选题)The "less than or equal to" comparison operator in Java is .

6. (单选题)What is 1 + 1 + 1 + 1 + 1 == 5?

7. (单选题)What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?

8. (单选题)The following code displays .double temperature = 50; if (temperature >= 100)System.out.println("too hot"); else if (temperature <= 40) System.out.println("too cold"); elseSystem.out.println("just right");

9. (单选题)Suppose x = 1, y = -1, and z = 1. What is the output of the following statement? (Please indent the statement correctly first.)if (x > 0) if (y > 0)System.out.println("x > 0 and y > 0"); else if (z > 0)System.out.println("x < 0 and z > 0");

10. (单选题)Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)?

11. (单选题)Given |x| >= 4, which of the following is true?

12. (单选题)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);}}

13. (单选题)How many times will the following code print "Welcome to Java"?int count = 0;while (count++ < 10) { System.out.println("Welcome to Java");}

14. (单选题)What will be displayed when the following code is executed?int number = 6; while (number > 0) { number -= 3;System.out.print(number + " ");}

15. (单选题)What is i after the following for loop?int y = 0;for (int i = 0; i < 10; ++i) { y += i;}

16. (单选题)Which of the following loops correctly computes 1/2 + 2/3 + 3/4 + ... + 99/100?

17. (单选题)What is the value in count after the following loop is executed?int count = 0; do {System.out.println("Welcome to Java");} while (count++ < 9); System.out.println(count);

18. (单选题)What is y after the following for loop statement is executed?int y = 0;for (int i = 0; i < 10; ++i) { y += 1;}

19. (单选题)What is the output after the following loop terminates?int number = 25; int i;boolean isPrime = true;for (i = 2; i < number; i++) { if (number % i == 0) { isPrime = false;break;}}System.out.println("i is " + i + " isPrime is " + isPrime);

20. (单选题)What is the number of iterations in the following loop?for (int i = 1; i < n; i++) {// iteration}

21. (单选题)Suppose the input for number is 9. What is the output from running the following program?import java.util.Scanner; public class Test {public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: ");

int number = input.nextInt();int i;boolean isPrime = true;for (i = 2; i < number && isPrime; i++) { if (number % i == 0) {isPrime = false;}}System.out.println("i is " + i);if (isPrime)System.out.println(number + " is prime"); elseSystem.out.println(number + " is not prime");}}

22. (单选题)Analyze the following code:import java.util.Scanner; public class Test {public static void main(String[] args) { int sum = 0;for (int i = 0; i < 100000; i++) {Scanner input = new Scanner(System.in); sum += input.nextInt();}}}

23. (单选题)How many times is the println statement executed?for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) System.out.println(i * j);

二. 多选题

24. (多选题)To add a value 1 to variable x, you write

25. (多选题)What is the output from System.out.println((int)Math.random() * 4)?

26. (多选题)Analyze the following code.int count = 0;while (count < 100) {// Point ASystem.out.println("Welcome to Java!"); count++;// Point B}// Point C

27. (多选题)Analyze the following code:public class Test {public static void main (String[] args) { int i = 0;for (i = 0; i < 10; i++); System.out.println(i + 4);}}

一、单选题

1. (单选题)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. 0
  • B. 1
  • C. 5
  • D. 6

我的答案: C

2. (单选题)Suppose x is 1. What is x after x -= 1?

  • A. 0
  • B. 1
  • C. 2
  • D. -1
  • E. -2

我的答案: A

3. (单选题)Which of the following is incorrect?

  • A. int x = 9;
  • B. long x = 9;
  • C. float x = 1.0;
  • D. double x = 1.0;

我的答案: C

4. (单选题)What is the value of (double)(5/2)?

  • A. 2
  • B. 2.5
  • C. 3
  • D. 2.0
  • E. 3.0

我的答案: D

5. (单选题)The "less than or equal to" comparison operator in Java is .

  • A. <
  • B. <=
  • C. =<
  • D. <<
  • E. !=

我的答案: B

6. (单选题)What is 1 + 1 + 1 + 1 + 1 == 5?

  • A. true
  • B. false
  • C. There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is true.

我的答案: A

7. (单选题)What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?

  • A. true
  • B. false
  • C. There is no guarantee that 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5 is true.

我的答案: C

8. (单选题)The following code displays .
double temperature = 50; if (temperature >= 100)
System.out.println("too hot"); else if (temperature <= 40) System.out.println("too cold"); else
System.out.println("just right");

  • A. too hot
  • B. too cold
  • C. just right
  • D. too hot too cold just right

我的答案: C

9. (单选题)Suppose x = 1, y = -1, and z = 1. What is the output of the following statement? (Please indent the statement correctly first.)
if (x > 0) if (y > 0)
System.out.println("x > 0 and y > 0"); else if (z > 0)
System.out.println("x < 0 and z > 0");

  • A. x > 0 and y > 0;
  • B. x < 0 and z > 0;
  • C. x < 0 and z < 0;
  • D. no output.

我的答案: B

10. (单选题)Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)?

  • A. 9
  • B. 10
  • C. 11

我的答案: B

11. (单选题)Given |x| >= 4, which of the following is true?

  • A. x >= 4 && x <= -4
  • B. x >= 4 || x <= -4
  • C. x >= 4 && x < -4
  • D. x >= 4 || x < -4

我的答案: B

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

我的答案: C

13. (单选题)How many times will the following code print "Welcome to Java"?
int count = 0;
while (count++ < 10) { System.out.println("Welcome to Java");
}

  • A. 8
  • B. 9
  • C. 10
  • D. 11
  • E. 0

我的答案: C

14. (单选题)What will be displayed when the following code is executed?
i

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sweep-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值