day05作业题干
java基础 循环结构测评题-答案
题目1(单选):
下列代码的运行结果是( A )
public class test {
public static void main(String[] args) {
int sum = 0;
int i=0;
// i = 0 1 2 3 4 5
while (i<=5){
if(i % 2 != 0){
// 1 3 5
sum += i;
}
i++;
}
System.out.println("sum = " + sum);
}
}
选项:
A. sum = 9
B. sum = 6
C. sum = 15
D. sum = 0
题目2(单选):
以下代码片段执行后,控制台的输出结果为( A )
public static void main(String[] args) {
int sum=0;
int i=1;