Professional Documents
Culture Documents
Home / Class 9 - APC Understanding Computer Applications with BlueJ / Nested for Loops
Chapter 9
Nested for Loops
Class 9 - APC Understanding Computer Applications with BlueJ
Monica - GPT-4 Ch
Monica
Question 1
Question 2
Question 3
Question 4
Question 5
Question 1
Question 2
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 1/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Question 3
Question 4
Question 5
Question 1
Question 2
Question 3
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 2/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Question 1
Question 2
Question 3
How will you terminate outer loop from the block of the
inner loop?
By using Labelled break statement.
Question 4
Question 5
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 3/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Question 1
int i,j;
for (i=0; i<4; i++)
{
for (j=i; j>=0; j--)
System.out.print(j);
System.out.println();
}
Output
0
10
210
3210
Explanation
For each iteration of outer for loop, inner for loop will
iterate from i to 0 printing the above pattern.
Question 2
int y,p;
for (int x=1; x<=3; x++)
{
for (y=1; y<=2; y++)
{
p = x * y;
System.out.print(p);
}
System.out.println( );
}
Output
12
24
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 4/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
36
Explanation
x y p Remarks
2 2
2 4
2 6
Question 3
int a,b;
for (a=1; a<=2; a++)
{
for (b= (64+a); b<=70; b++)
System.out.print((char) b);
System.out.println( );
}
Output
ABCDEF
BCDEF
Explanation
In the first iteration of outer for loop, the inner for loop will
print characters with ASCII codes from 65 to 70 i.e. letters
from A to F.
In the second iteration of outer for loop, the inner for loop
will print characters with ASCII codes from 66 to 70 i.e.
letters from B to F.
Question 4
int x,y;
for(x=1; x<=5; x++)
{
for(y=1; y<x; y++)
{
if(x == 4)
break;
System.out.print(y);
}
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 5/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
System.out.println( );
}
Output
1
12
1234
Explanation
Question 5
int i,j;
first:
for (i=10; i>=5; i--)
{
for (j= 5; j<=i; j++)
{
if (i*j <40)
continue first;
System.out.print(j);
}
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 6/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
System.out.println( );
}
Output
5678910
56789
5678
Explanation
For the first 3 iterations of outer loop i * j >= 40. After that
as the condition of if (i*j <40) becomes true, in each
iteration of inner for, continue statement transfers the
program control to the next iteration of outer for loop.
Solutions to Unsolved Java Programs
Question 1
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 7/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 8/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Question 2
import java.util.Scanner;
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 9/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
}
}
if (isPrime)
System.out.println(n + " is a Prime Nu
}
}
}
Output
Question 3
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 10/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
import java.util.Scanner;
Output
Question 4
(a)
*
* #
* # *
* # * #
* # * # *
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 11/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
for (int j = 1; j <= i; j++) {
if (j % 2 == 0)
System.out.print("# ");
else
System.out.print("* ");
}
System.out.println();
}
}
}
Output
(b)
54321
5432
543
54
5
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 12/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
CONTENTS
Chapter 1 - Unit 1
Principles of Object Oriented Fill in the blanks
Programming
Question 5 Write whether the following
statements are True/False
Chapter 1 - Unit 2
Differentiate between the
Introduction to Java following
Write a program to calculate and display the factorials of Answer the following
Chapter 2 questions
Elementary Concept of Object and all the numbers between 'm' and 'n' (where m<n, m>0, Give the output of the
Classes following snippets based on
n>0). nested loops
Chapter 3 Solutions to Unsolved Java
Programs
Values and Data Types
[Hint: factorial of 5 means: 5!=5*4*3*2*1]
Video Explanations
Chapter 4
Operators in Java
import java.util.Scanner;
Chapter 5
Input In Java
Chapter 6
public class KboatFactRange
Mathematical Library Methods {
Chapter 7
public static void main(String args[]) {
Conditional Statements In Java
}
}
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 13/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Question 6
import java.util.Scanner;
switch (choice) {
case 1:
for (int i = 2; i <= 100; i++) {
boolean isPrime = true;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime)
System.out.println(i);
}
break;
case 2:
System.out.println(1);
for (int i = 2; i <= 100; i++) {
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 14/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
boolean isPrime = true;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (!isPrime)
System.out.println(i);
}
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 15/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Question 7
import java.util.Scanner;
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 16/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
in.nextLine();
String name = in.nextLine();
System.out.print("Marks in English: ");
int engMarks = in.nextInt();
System.out.print("Marks in Science: ");
int sciMarks = in.nextInt();
System.out.print("Marks in Maths: ");
int mathsMarks = in.nextInt();
double avgMarks = (engMarks + sciMarks + m
totalMarks += avgMarks;
System.out.println("Average marks of " + n
}
Output
Question 8
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 17/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
import java.util.Scanner;
if (num == 1) {
System.out.println(num + " is not a twiste
}
else {
boolean isPrime = true;
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
int t = num;
int revNum = 0;
while (t != 0) {
int digit = t % 10;
t /= 10;
revNum = revNum * 10 + digit;
}
if (isPrime)
System.out.println(num + " is a tw
else
System.out.println(num + " is not
}
}
}
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 18/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Question 9
import java.util.Scanner;
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 19/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
import java.util.Scanner;
Output
import java.util.Scanner;
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 20/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
}
}
Output
import java.util.Scanner;
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 21/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Output
Question 10
(a)
1
21
321
4321
54321
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 22/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
for (int j = i; j >= 1; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
Output
(b)
12345
1234
123
12
1
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 23/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
(c)
54321
5432
543
54
5
Output
(d)
13579
1357
135
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 24/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
13
1
Output
(e)
5
54
543
5432
54321
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 25/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
(f)
12345
2345
345
45
5
Output
(g)
99999
77777
55555
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 26/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
33333
11111
Output
(h)
9
79
579
3579
13579
Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 27/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
(i)
9
97
975
9753
97531
Output
(j)
1
23
456
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 28/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
7 8 9 10
11 12 13 14 15
Output
Video Explanations
Prev Next
Iterative Constructs In Java More on Basic Input/Output
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 29/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Class - 6 Effective History & Civics Solutions Java Number Programs (ICSE Classes 9 / 10) Privacy Policy
Class - 6 APC Understanding Computers Solutions Java Number Programs (ISC Classes 11 / 12) Terms of Service
Class - 7 Concise Physics Selina Solutions Output Questions for Class 10 ICSE Computer Applications
Class - 7 Concise Chemistry Selina Solutions Algorithms & Flowcharts for ICSE Computers
Class - 7 Dalal Simplified Middle School Chemistry Solutions ICSE Class 8 Computers Differentiate Between the Following
Class - 7 Living Science Biology Ratna Sagar Solutions Class - 9 NCERT Science Solutions
Class - 7 Around the World Geography Solutions Class - 9 NCERT Geography Contemporary India 1 Solutions
Class - 7 Veena Bhargava Geography Solutions Class - 9 Sumita Arora Computer Code 165 Solutions
Class - 7 Effective History & Civics Solutions Class - 9 Kips Cyber Beans Computer Code 165 Solutions
Class - 8 Concise Physics Selina Solutions Class - 10 NCERT Geography Contemporary India 2 Solutions
Class - 8 Concise Chemistry Selina Solutions Class - 10 Sumita Arora Computer Code 165 Solutions
Class - 8 Dalal Simplified Middle School Chemistry Solutions Class - 10 Kips Cyber Beans Computer Code 165 Solutions
Class - 8 Concise Biology Selina Solutions Class - 11 CBSE Sumita Arora Python Solutions
Class - 8 Living Science Biology Ratna Sagar Solutions Class - 12 CBSE Sumita Arora Python Solutions
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 30/31
1/14/24, 2:04 PM Chapter 9: Nested for Loops | Solutions for Class 9 ICSE APC Understanding Computer Applications With BlueJ & Java Prog…
Class - 10 ML Aggarwal Mathematics Solutions
https://www.knowledgeboat.com/learn/class-9-icse-understanding-computer-applications-bluej/solutions/kxJqV/nested-for-loops-in-java 31/31