Java Pattern Programs
1.Write a program in Java to display the following pattern:
1
22
333
4444
55555
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++)
System.out.print(i + " ");
System.out.println();
}
}
}
2.Write a program in Java to display the following pattern:
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 5; i >= 1; i--) {
for (int j = i; j >= 1; j--)
System.out.print( j + " ");
System.out.println();
}
}
}
3. Write the program in Java to display the following pattern:
1
21
321
4321
54321
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = i; j >= 1; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
4. Write a program in Java to display the following pattern:
54321
5432
543
54
5
public class KboatPattern
{
public void displayPattern() {
for (int i = 1; i <= 5; i++) {
for (int j = 5; j >= i; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
5. Write a program in Java to display the following pattern:
3
44
555
6666
77777
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 3; i <= 7; i++) {
for (int j = 3; j <= i; j++)
System.out.print(i);
System.out.println();
}
}
}