Font size
WorksheetsMK Java for-Loop Quiz 2
Total questions: 10
Worksheet time: 5mins
To execute a for-loop the condition must be true in the beginning.
True
False
The for-loop is an exit-controlled loop.
True
False
Which of the following is not a loop in Java?
while
for
repeat-until
do-while
Which of the following is not a jump statement in Java?
return
break
continue
goto
Which of the following is an exit-controlled loop?
while
for
do-while
repeat-until
How many times will the following code print "Hello"?
for(int i = 1; i <7; i+=1)
{
System.out.println("Hello");
}
0
7
6
1
What value of sum will be printed for the following piece of code:
int sum = 0;
for (int i = 0; i < 5; i++)
{
sum = i;
}
System.out.println(sum);
0
1
4
5
10
What value of adder will be printed for the following piece of code:
int adder = 0;
for (int i = 0; i < 5; i++)
{
adder += i;
}
System.out.println(adder);
0
5
10
15
How many times will the following loop execute and what value of sum will be displayed? TWO ANSWERS are to be checked.
int add = 10;
for (int i = 1; i > 5; i++)
{
add+=i;
}
System.out.println(add);
15
25
10
0
5
What will be the value of d at the end of execution of the following piece of code?
int d = 1;
for(int i = 2; i <=5; i++)
{
d = d * i;
}
System.out.println(d);
(a)
