Write the output : -
int a;
for(a=1;i<=5;a++);
System.out.println(a); System.out.println(a);
Looping in java
Quiz
•
Computers
•
9th Grade
•
Hard
RAJ PANDEY
Used 59+ times
FREE Resource
7 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Write the output : -
int a;
for(a=1;i<=5;a++);
System.out.println(a); System.out.println(a);
6
6
1
2
3
4
5
6
6
Compile time error
Runtime error
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How many times 'Hello' is printed?
public class Test1 {
public static void main(){
for(int i = 0; i<5; i++) {
System.out.println("Hello");
break;
}
}
}
1
4
5
6
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the following program?
class Test2 {
public static void main(String s[]) {
for(int i = 0; i <= 5; i++ ) {
System.out.println("i = " + i );
}
System.out.println("i after the loop = " + i );
}
}
i=0
i=1
i=2
i=3
i=4
i after the loop=5
i=0
i=1
i=2
i=3
i=4
i=5
i after the loop=6
i=0
i=1
i=2
i=3
i=4
i=5
i after the loop=5
0=0
1=1
2=2
3=3
4=4
5=5
6 after the loop=6
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the following program?
class ForSample
{
public static void main(String s[])
{
int i = 0;
for(;i <= 5; i++ )
{
System.out.println("i = " + i );
}
System.out.println("i after the loop = " + i );
}
}
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i after the loop = 6
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
Compilation Errors
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the following program?
class ForSample
{
public static void main(String s[])
{
for(int i = 10; i <= 5; i-- )
{
System.out.println("i = " + i );
}
}
}
i = 10
i = 9
i = 8
i = 7
i = 6
i = 10
i = 9
i = 8
i = 7
i = 6
i = 5
i = 4
i = 3
i = 2
i = 1
No output
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the following program?
class Factorial
{
public static void main(String s[])
{
int number = 5;
int factorial = 1;
for(int i = 2; i <= number; i++ )
{
factorial *= factorial;
}
System.out.println("Factorial of 5 is " + factorial);
}
}
Factorial of 5 is 1
Factorial of 5 is 120
Compilation Errors
Factorial of 5 is 625
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the following program?class MultiVariableFor{
public static void main(String s[]) {
int a, b;
for(a = 1, b = 4; a < b; a++, b-)
{
System.out.println("a = " + a);
System.out.println("b = " + b);
} }}
Compilation error since both a++ and b--
should not be present in the iteration section (i.e after the second semicolon)
a = 1
b = 4
a = 2
b = 3
a = 3
b = 2
a = 1
b = 4
a = 2
b = 3
Compilation error since both a = 1 and b = 4
should not be present in the initialization section (i.e before the first semicolon)
10 questions
Computer Quiz(Java)(16-10-2020)
Quiz
•
9th Grade
10 questions
Introduction to Arrays
Quiz
•
KG - University
10 questions
Week 3 Arduino Basics Quiz
Quiz
•
7th - 12th Grade
10 questions
AP Computer Science-Quiz 2(G10)
Quiz
•
9th - 12th Grade
9 questions
quis lat soal
Quiz
•
9th - 12th Grade
8 questions
Quiz P2
Quiz
•
9th Grade - University
11 questions
Java1
Quiz
•
6th - 11th Grade
10 questions
AP CSA Unit 1 & 2 Review
Quiz
•
9th - 12th Grade
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade
17 questions
Parts of Speech
Quiz
•
7th - 12th Grade
20 questions
Chapter 3 - Making a Good Impression
Quiz
•
9th - 12th Grade
20 questions
Inequalities Graphing
Quiz
•
9th - 12th Grade
10 questions
Identifying equations
Quiz
•
KG - University