选择
题目1:If number is an Integer, analyze the following code:
Code 1:
boolean even;
if (number % 2 == 0)
even = true;else even = false;
Code 2:
boolean even = (number % 2 == 0);
选择一项:
Code 2 has syntax errors.
Both Code 1 and Code 2 have syntax errors.
Code 1 has syntax errors.
Both Code 1 and Code 2 are correct, but Code 2 is better.
反馈
正确答案是:Both Code 1 and Code 2 are correct, but Code 2 is better.
题目2
What is the output of the following switch statement char ch = ‘a’; switch (ch) { case ‘a’: case ‘A’: System.out.print(ch); break; case ‘b’: case ‘B’: System.out.print(ch); break; case ‘c’: case ‘C’: System.out.print(ch); break; case ‘d’: case ‘D’: System.out.print(ch); }
选择一项:
ab
aa
abcd
a
abc
反馈
正确答案是:a
题目3
What is x after evaluating x = (2 > 3) ? 2 : 3;
选择一项:
2
3
4
5
反馈
正确答案是:3
题目4
正确
获得1.00分中的1.00分
未标记标记题目
题干
Which of the following is a constant, according to Java naming conventions?
选择一项:
MAX_VALUE
Test
ReadInt
read
反馈
正确答案是:MAX_VALUE
题目5
正确
获得1.00分中的1.00分
未标记标记题目
题干
What is y after the following switch statement? int x = 0; int y = 0; switch (x + 1) { case 0: y = 0; case 1: y = 1; default: y = -1 }
选择一项:
-1
2
0
1
反馈
正确答案是:-1
题目6
正确
获得1.00分中的1.00分
未标记标记题目
题干
To declare a constant MAX_LENGTH inside a method with value 99.98, you write
选择一项:
final float MAX_LENGTH = 99.98;
final double MAX_LENGTH = 99.98;
final MAX_LENGTH = 99.98;
double MAX_LENGTH = 99.98;
反馈
正确答案是:final double MAX_LENGTH = 99.98;
题目7
正确
获得1.00分中的1.00分
未标记标记题目
题干
Which of the following code displays the area of a circle if the radius is positive.
选择一项:
if (radius <= 0) System.out.println(radius * radius * 3.14159);
if (radius > 0) System.out.println(radius * radius * 3.14159);
if (radius != 0) System.out.println(radius * radius * 3.14159);
if (radius >= 0) System.out.println(radius * radius * 3.14159);
反馈
正确答案是:if (radius > 0) System.out.println(radius * radius * 3.14159);
题目8
正确
获得1.00分中的1.00分
未标记标记题目
题干
The expression (int)(76.0252175 * 100) / 100 evaluates to _________.
选择一项:
76.02
76.03
76.0252175
76
反馈
正确答案是:76
题目9
正确
获得1.00分中的1.00分
未标记标记题目
题干
Analyze the following code. int x = 0; if (x > 0); { System.out.println(“x”); }
选择一项:
The symbol x is always printed twice.
The symbol x is always printed.
The value of variable x is always printed.
Nothing is printed because x > 0 is false.
反馈
正确答案是:The symbol x is always printed.
题目10
正确
获得1.00分中的1.00分
未标记标记题目
题干
What is y after the following switch statement is executed?x = 3;switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1;}
选择一项:
1
2
3
4
0
反馈
正确答案是:2
题目11
正确
获得1.00分中的1.00分
未标记标记题目
题干
Assume x is 0. What is the output of the following statement?if (x > 0) System.out.print(“x is greater than 0”);else if (x < 0) System.out.print(“x is less than 0”);else System.out.print(“x equals 0”);
选择一项:
x is greater than 0
x equals 0
x is less than 0
None
反馈
正确答案是:x equals 0
编程
题目1
正确
获得10.00分中的7.00分
未标记标记题目
题干
编写一个Java程序在屏幕上输出1!+2!+3!+……+n!的和。
For example:
Input Result
10`
1!+2!+3!+……+10!= 4037913
Answer:(penalty regime: 10, 20, … %)
Ace editor not ready. Perhaps reload page?
Falling back to raw text area.
public class jiecheng {
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum1=0;
for(int i=1;i<=10;i++) {
int sum2=1;
for(int j=1;j<=i;j++ ){
sum2*=j;
}
sum1+=sum2;
}
System.out.println("1!+2!+3!+……+10!= "+sum1);
}
}
题目2
正确
获得10.00分中的10.00分
未标记标记题目
题干
利用递归方法求5!。
程序分析:递归公式:f(n)=f(n-1)*4!
import java.util.*;
public class digui {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner gx=new Scanner(System.in);
int n=gx.nextInt();
F fum=new F();
System.