Contents: Click for quick access
11. Write a program to display following pattern. 5 4 4 3 3 3 2 2 2 2 1 1 1 1 112. Write a program to display following pattern . 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5 , 13. Write a program to display following pattern. 5 5 4 5 4 3 5 4 3 2 5 4 3 2 1 , 14. Write a program to display following pattern. 5 4 3 2 1 5 4 3 2 5 4 3 5 4 5 ,15. Write a program to display following pattern. 6 6 6 6 6 6 4 4 4 4 2 2 ,16. Write a program to display following pattern. 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 , 17. Write a program to display following pattern. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ,18. Write a program to display following pattern. 1 1 1 1 1 1 1 1 1 1 ,19. Write a program to display following pattern. 2 2 2 2 2 2 2 2 2 2 ,20.Write a program to display following pattern . 3 3 3 3 3 3 3 3 3 3 ,
I’ve included a list of some of the Java programs below. You may also view all of the Java programs on our mobile app. I strongly advise you to use our mobile app for a better experience.
Please click the link to get our app–> https://play.google.com/store/apps/details?id=com.allbachelor.javaapp&hl=en&gl=US
11. Write a program to display following pattern.
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
import java.util.Scanner;
class Patterns {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int row = sc.nextInt();
for (int i = row; i >= 1; i--) {
for (int j = i; j < = 5; j++) {
System.out.print(i+\" \");
}
System.out.println();
}
}
}
12. Write a program to display following pattern .
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5 ,
import java.util.Scanner;
class Patterns {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int row = sc.nextInt();
for (int i = 1; i < = 5; i++) {
for (int j = i; j < = 5; j++) {
System.out.print(i+" ");
}
System.out.println();
}
}
}
13. Write a program to display following pattern.
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1 ,
import java.util.Scanner;
class Patterns {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int row = sc.nextInt();
for (int i = row; i >= 1; i--) {
for (int j = row; j >= i; j--) {
System.out.print(j+" ");
}
System.out.println();
}
}
}
14. Write a program to display following pattern.
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5 ,
import java.util.Scanner;
class Patterns {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int row = sc.nextInt();
for (int i = 1; i < = row; i++) {
for (int j = row; j >= i; j--) {
System.out.print(j+" ");
}
System.out.println();
}
}
}
15. Write a program to display following pattern.
6 6 6 6 6 6
4 4 4 4
2 2 ,
class Patterns {
public static void main(String[] args) {
for (int i = 6; i >= 2; i=i-2) {
for (int j = 1; j < = i; j++) {
System.out.print(i+" ");
}
System.out.println();
}
}
}
16. Write a program to display following pattern.
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1 ,
class Patterns {
public static void main(String[] args) {
int a=1;
for (int i = 1; i < = 4; i++) {
System.out.println(a*a);
a=a*10+1;
}
}
}
17. Write a program to display following pattern.
1 1 1 1 1
1 1 1 1
1 1 1
1 1
1 ,
class Patterns {
public static void main(String[] args) {
int a=11111;
for (int i = 1; i < = 5; i++) {
System.out.println(a);
a=a/10;
}
}
}
18. Write a program to display following pattern.
1
1 1
1 1 1
1 1 1 1 ,
class Patterns {
public static void main(String[] args) {
int a=1;
for (int i = 1; i < = 4; i++) {
System.out.println(a);
a=a*10+1;
}
}
}
19. Write a program to display following pattern.
2 2 2 2
2 2 2
2 2
2 ,
class Patterns {
public static void main(String[] args) {
int a=2222;
for (int i = 1; i < = 4; i++) {
System.out.println(a);
a=a/10;
}
}
}
20.Write a program to display following pattern .
3
3 3
3 3 3
3 3 3 3 ,
class Patterns {
public static void main(String[] args) {
int a=3;
for (int i = 1; i < = 4; i++) {
System.out.println(a);
a=a*10+3;
}
}
}