Java Programming – Loops Based
Output Questions
Subject: Computer Science
Topic: Java Loops – Output Based Questions
Total Marks: 30
Time: 1 Hour
Instructions:
- Attempt all questions.
- Show the output only.
- Each question carries equal marks unless specified otherwise.
Section A: Output Based Questions [5 x 6 = 30 marks]
1. Q1. What will be the output of the following code?
for(int i = 1; i <= 5; i++) {
for(int j = 1; j <= i; j++) {
[Link]("*");
}
[Link]();
}
2. Q2. What will be the output of the following code?
for(int i = 5; i >= 1; i--) {
for(int j = 1; j <= i; j++) {
[Link](j);
}
[Link]();
}
3. Q3. Predict the output:
int i = 1;
while(i <= 5) {
[Link](i + " ");
i++;
}
4. Q4. What will be the output?
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 3; j++) {
[Link](i * j + " ");
}
[Link]();
}
5. Q5. What will this code print?
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
if(i == j)
[Link]("#");
else
[Link]("*");
}
[Link]();
}
Answer Key
Q1. Output:
*
**
***
****
*****
Q2. Output:
12345
1234
123
12
1
Q3. Output:
12345
Q4. Output:
123
246
369
Q5. Output:
#***
*#**
**#*
***#