0% found this document useful (0 votes)
10 views3 pages

Java Nested While Loop Examples

Uploaded by

ehtsalman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Java Nested While Loop Examples

Uploaded by

ehtsalman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Programs on Nested while Loops

1. Multiplication Table (1 to 5)
--------------------------------
class MultiplicationTable {
public static void main(String[] args) {
int i = 1;
while (i <= 5) {
int j = 1;
while (j <= 5) {
[Link]((i * j) + "\t");
j++;
}
[Link]();
i++;
}
}
}

2. Square Pattern of Stars


---------------------------
class SquarePattern {
public static void main(String[] args) {
int i = 1;
while (i <= 5) {
int j = 1;
while (j <= 5) {
[Link]("* ");
j++;
}
[Link]();
i++;
}
}
}

3. Right Triangle Pattern


--------------------------
class RightTriangle {
public static void main(String[] args) {
int i = 1;
while (i <= 5) {
int j = 1;
while (j <= i) {
[Link]("* ");
j++;
}
[Link]();
i++;
}
}
}

4. Inverted Triangle Pattern


-----------------------------
class InvertedTriangle {
public static void main(String[] args) {
int i = 5;
while (i >= 1) {
int j = 1;
while (j <= i) {
[Link]("* ");
j++;
}
[Link]();
i--;
}
}
}

5. Number Pyramid
------------------
class NumberPyramid {
public static void main(String[] args) {
int i = 1;
while (i <= 5) {
int j = 1;
while (j <= i) {
[Link](j + " ");
j++;
}
[Link]();
i++;
}
}
}

6. Hollow Square
-----------------
class HollowSquare {
public static void main(String[] args) {
int n = 5;
int i = 1;
while (i <= n) {
int j = 1;
while (j <= n) {
if (i == 1 || i == n || j == 1 || j == n)
[Link]("* ");
else
[Link](" ");
j++;
}
[Link]();
i++;
}
}
}

You might also like