The first chapter Java language basic knowledge-1.4-algorithm flow control
Multiple choice questions (1 point)
1 What kind of control statement is the if statement in a Java program:
A
Branch control statement
B
loop statement
C
Jump statement
D
Termination statement
2 Which of the following if statements does not belong to the Java language:
A
Only "if" statement
B
Only "else" sentence
C
"If"-"else" statement
D
“if”-“else if”-“else”语句
3 Which of the following conditional calculations is equivalent to a simple if-else statement: if(a> b) System.out.println(a); else System.out.println (b);
A
System.out.println((a>b):a?b);
B
System.out.println((a>b):b?a);
C
System.out.println((a>b)?b:a);
D
System.out.println((a>b)?a:b);
4 Which of the following structures does not belong to the flow control structure of Java:
A
Sequence structure
B
Select structure
C
Cyclic structure
D
Flip structure
5 The following data types that cannot be used as switch expression parameters are:
A
int
B
char
C
long
D
short
6 Given the following program segment, as follows:
int i=0, j=-1;
switch(i)
{ case 0: j=1; case 2: j=2; default: j=5; } System.out.print ("j="+j); Compile and run, the correct result is:
A
j=-1
B
j=1
C
j=2
D
j=5
7
The following is wrong about the switch statement:
A
In the same switch statement, the value after case can be the same
B
Can compile and run without break statement
C
The default statement is optional
D
The value of the expression in the switch statement can be of type String
8 Examine the following program code:
int num1=40;
int num2=5;
int ans=0;
if(num1/5==num2) {ans=10;}
if(num2%5==0) {ans=20 ;}
if(num2==0) {ans=30;}
else {ans=40;}
System.out.println("answer is:" + ans); Which of the following is the output of the program:
A
answer is: 30
B
answer is: 20
C
answer is: 10
D
answer is: 40
9 Assuming int x=4, y=100, how many times is the loop body of the following statement executed:
while(y/x>3) { if(y%x>3) x=x +1; else y=y/ x; }
A
1 time
B
2 times
C
3 times
D
4 times
10 The output result of the following program segment is:
int i = 0;
for(i=4; i>0; i--) { if(i==1) break; System.out.print(i); } System. out.print(i);
A
4321
B
4322
C
321
D
432