1. Assume that all variables in the following code are properly declared and tha
ID: 3812690 • Letter: 1
Question
1.
Assume that all variables in the following code are properly declared and that the input is 3 7 4 –1. The output is 13.
num = console.nextInt();
sum = num;
while (num != -1)
{
num = console.nextInt();
sum = sum + num;
}
System.out.println(sum);
False
2.
int i;
for (i = 0; i <= 10; i++)
System.out.println("*");
System.out.println("!");
Which of the following is the initial expression in the for loop above?
i = 0;
i <= 10;
i++
d. System.out.println("*");
3.
int i;
for (i = 0; i <= 10; i++)
System.out.println("*");
System.out.println("!");
Which of the following is the update expression in the for loop above?
i = 0;
i <= 10;
i++
d. System.out.println("*");
TrueFalse
2.
int i;
for (i = 0; i <= 10; i++)
System.out.println("*");
System.out.println("!");
Which of the following is the initial expression in the for loop above?
i = 0;
b.i <= 10;
c.i++
d. System.out.println("*");
3.
int i;
for (i = 0; i <= 10; i++)
System.out.println("*");
System.out.println("!");
Which of the following is the update expression in the for loop above?
a.i = 0;
b.i <= 10;
c.i++
d. System.out.println("*");
Explanation / Answer
Question 1
Answer: True
The output of the above code is 13 because we are adding all eleenets that are read from console.
Question 2
Answer: i = 0;
The initial expression of the for loop is i = 0;
Question 3
Answer: i++
i++ is the updated expression in for loop.
for ([initial-expression]; [condition]; [increment-expression])
{
statements
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.