当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1514:选择题(期中模拟用)

题目描述

请修改下面的程序,在对应的位置填入对应选择题的答案(采用大写字母)。
选择题如下:
1 A Java program is best classified as
A)hardware
B)software
C)storage
D)processor
E)input

2 The main method for a Java program is defined by
A)public static main( )
B)public static main(String[ ] args);
C)public static main(String[ ] args)
D)private static main(String[ ] args)
E)the main method could be defined as in a, c or d but not b

3 If x is an int and y is a float, all of the following are legal except which assignment statement?
A)y = x;
B)x = y;
C)y = (float) x;
D)x = (int) y;
E)all of the above are legal

4 Consider the following two lines of code.  What can you say about s1 and s2?
 String s1 = "testing" + "123";
 String s2 = new String("testing 123");
A)s1 and s2 are both references to the same String object
B)the line declaring s2 is legal Java; the line declaring s1 will produce a syntax error
C)s1 and s2 are both references to different String objects
D)s1 and s2 will compare “equal”
E)none of the above

5 A variable whose scope is restricted to the method where it was declared is known as a(n)
A)parameter
B)global variable
C)local variable
D)public instance data
E)private instance data

6 Consider a method defined with the header:  public void foo(int a, int b).   Which of the following method calls is legal?
A)foo(0, 0.1);
B)foo(0 / 1, 2 * 3);
C)foo(0);
D)foo( );
E)foo(1 + 2, 3 * 0.1);

7 Consider the following code that will assign a letter grade of ‘A’, ‘B’, ‘C’, ‘D’, or ‘F’ depending on a student’s test score. 
if (score >= 90) grade = 'A';
if (score >= 80) grade = 'B';
if (score >= 70) grade = 'C';
if (score >= 60) grade = 'D';
else grade = ‘F’;
A)This code will work correctly in all cases
B)This code will work correctly only if grade >= 60
C)This code will work correctly only if grade < 60
D)This code will work correctly only if grade < 70
E)This code will not work correctly under any circumstances

8 Assume that x and y are int variables with x = 5, y = 3, and a and d are char variables with a = 'a' and d = 'A', and examine the following conditions:
Condition 1:  (x < y && x > 0)
Condition 2:  (a != d || x != 5)
Condition 3:  !(true && false)
Condition 4:  (x > y || a == 'A' || d != 'A')
A)All 4 Conditions are true
B)Only Condition 2 is true
C)Condition 2 and Condition 4 are true only
D)Conditions 2, 3 and 4 are all true, Condition 1 is not
E)All 4 Conditions are false

9 How many times will the following loop iterate?
int x = 10;
do  {
  System.out.println(x);
                 x--;
           } while (x > 0);
A)0 times
B)1 time
C)9 times
D)10 times
E)11 times

10 Which of the following loops would adequately add 1 to each element stored in values?
A)for (j=1; j<values.length; j++)  values[j]++;
B)for (j=0; j<values.length; j++)  values[j]++;
C)for (j=0; j<=values.length; j++)  values[j]++;
D)for (j=0; j<values.length–1; j++) values[j]++;
E)for (j=1; j<values.length–1; j++)  values[j]++;

程序如下:
import java.util.Scanner;

public class Main {

 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
  int choice = input.nextInt();
  switch (choice) {
  case 1:
   System.out.println("X"); // 请将X修改成第1题答案
   break;
  case 2:
   System.out.println("X"); // 请将X修改成第2题答案
   break;
  case 3:
   System.out.println("X"); // 请将X修改成第3题答案
   break;
  case 4:
   System.out.println("X"); // 请将X修改成第4题答案
   break;
  case 5:
   System.out.println("X"); // 请将X修改成第5题答案
   break;
  case 6:
   System.out.println("X"); // 请将X修改成第6题答案
   break;
  case 7:
   System.out.println("X"); // 请将X修改成第7题答案
   break;
  case 8:
   System.out.println("X"); // 请将X修改成第8题答案
   break;
  case 9:
   System.out.println("X"); // 请将X修改成第9题答案
   break;
  case 10:
   System.out.println("X"); // 请将X修改成第10题答案
   break;
  default:
   System.out.println("X");
  }

 }

}

 

输入解释

输入一个选择题题号

输出解释
输出对应的答案(采用大写字母)
输入样例
1
输出样例
B


该题目包含在题集 SSPU

题目来源 sspu

共提交 307

通过率 19.54%
时间上限 内存上限
1000 MS 128 MB