Java Pattern
Java Pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 45
1 2 3 456
1 2 3 4567
Java Program :
import java.util.Scanner;
System.out.println();
}
sc.close();
}
}
Output :
Pattern 2 :
1
2 2
3 3 3
4 4 4 4
5 5 5 55
6 6 6 666
7 7 7 7777
Java Program :
import java.util.Scanner;
System.out.println();
}
sc.close();
}
}
Output :
Pattern 3 :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 56
1 2 3 4 567
1 2 3 4 56
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Java Program :
1. import java.util.Scanner;
2.
3. public class MainClass
4. {
5. public static void main(String[] args)
6. {
7. Scanner sc = new Scanner(System.in);
8.
9. //Taking rows value from the user
10.
11. System.out.println("How many rows you want in this pattern?");
12.
13. int rows = sc.nextInt();
14.
15. System.out.println("Here is your pattern....!!!");
16.
17. //Printing upper half of the pattern
18.
19. for (int i = 1; i <= rows; i++)
20. {
21. for (int j = 1; j <= i; j++)
22. {
23. System.out.print(j+" ");
24. }
25.
26. System.out.println();
27. }
28.
29. //Printing lower half of the pattern
30.
31. for (int i = rows-1; i >= 1; i--)
32. {
33. for (int j = 1; j <= i; j++)
34. {
35. System.out.print(j+" ");
36. }
37.
38. System.out.println();
39. }
40.
41. //Closing the resources
42.
43. sc.close();
44. }
45. }
Output :
Pattern 4 :
1 2 3 4567
1 2 3 456
1 2 3 45
1 2 3 4
1 2 3
1 2
1
Java Program :
1. import java.util.Scanner;
2.
3. public class MainClass
4. {
5. public static void main(String[] args)
6. {
7. Scanner sc = new Scanner(System.in);
8.
9. //Taking rows value from the user
10.
11. System.out.println("How many rows you want in this pattern?");
12.
13. int rows = sc.nextInt();
14.
15. System.out.println("Here is your pattern....!!!");
16.
17. for (int i = rows; i >= 1; i--)
18. {
19. for (int j = 1; j <= i; j++)
20. {
21. System.out.print(j+" ");
22. }
23.
24. System.out.println();
25. }
26.
27. //Closing the resources
28.
29. sc.close();
30. }
31. }
Output :
[quads id=5]
Pattern 5 :
7 6 5 4321
7 6 5 432
7 6 5 43
7 6 5 4
7 6 5
7 6
7
Java Program :
1. import java.util.Scanner;
2.
3. public class MainClass
4. {
5. public static void main(String[] args)
6. {
7. Scanner sc = new Scanner(System.in);
8.
9. //Taking rows value from the user
10.
11. System.out.println("How many rows you want in this pattern?");
12.
13. int rows = sc.nextInt();
14.
15. System.out.println("Here is your pattern....!!!");
16.
17. for (int i = 1; i <= rows; i++)
18. {
19. for (int j = rows; j >= i; j--)
20. {
21. System.out.print(j+" ");
22. }
23.
24. System.out.println();
25. }
26.
27. //Closing the resources
28.
29. sc.close();
30. }
31. }
Output :
Pattern 6 :
7
7 6
7 6 5
7 6 5 4
7 6 5 43
7 6 5 432
7 6 5 4321
Java Program :
1. import java.util.Scanner;
2.
3. public class MainClass
4. {
5. public static void main(String[] args)
6. {
7. Scanner sc = new Scanner(System.in);
8.
9. //Taking rows value from the user
10.
11. System.out.println("How many rows you want in this pattern?");
12.
13. int rows = sc.nextInt();
14.
15. System.out.println("Here is your pattern....!!!");
16.
17. for (int i = rows; i >= 1; i--)
18. {
19. for (int j = rows; j >= i; j--)
20. {
21. System.out.print(j+" ");
22. }
23.
24. System.out.println();
25. }
26.
27. //Closing the resources
28.
29. sc.close();
30. }
31. }
Output :
Pattern 7 :
7 6 5 4321
6 5 4 321
5 4 3 21
4 3 2 1
3 2 1
2 1
1
Java Program :
1. import java.util.Scanner;
2.
3. public class MainClass
4. {
5. public static void main(String[] args)
6. {
7. Scanner sc = new Scanner(System.in);
8.
9. //Taking rows value from the user
10.
11. System.out.println("How many rows you want in this pattern?");
12.
13. int rows = sc.nextInt();
14.
15. System.out.println("Here is your pattern....!!!");
16.
17. for (int i = rows; i >= 1; i--)
18. {
19. for (int j = i; j >= 1; j--)
20. {
21. System.out.print(j+" ");
22. }
23.
24. System.out.println();
25. }
26.
27. //Closing the resources
28.
29. sc.close();
30. }
31. }
Output :
Pattern 8 :
1 2 3 4567
1 2 3 456
1 2 3 45
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 45
1 2 3 456
1 2 3 4567
Java Program :
1. import java.util.Scanner;
2.
3. public class MainClass
4. {
5. public static void main(String[] args)
6. {
7. Scanner sc = new Scanner(System.in);
8.
9. //Taking rows value from the user
10.
11. System.out.println("How many rows you want in this pattern?");
12.
13. int rows = sc.nextInt();
14.
15. System.out.println("Here is your pattern....!!!");
16.
17. //Printing upper half of the pattern
18.
19. for (int i = rows; i >= 1; i--)
20. {
21. for (int j = 1; j <= i; j++)
22. {
23. System.out.print(j+" ");
24. }
25.
26. System.out.println();
27. }
28.
29. //Printing lower half of the pattern
30.
31. for (int i = 2; i <= rows; i++)
32. {
33. for (int j = 1; j <= i; j++)
34. {
35. System.out.print(j+" ");
36. }
37.
38. System.out.println();
39. }
40.
41. //Closing the resources
42.
43. sc.close();
44. }
45. }
Output :
Pattern 9 :
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 321
1 2 3 4 5 6 54321
1 2 3 4 5 6 7654321
Java Program :
1. import java.util.Scanner;
2.
3. public class MainClass
4. {
5. public static void main(String[] args)
6. {
7. Scanner sc = new Scanner(System.in);
8.
9. //Taking rows value from the user
10.
11. System.out.println("How many rows you want in this pattern?");
12.
13. int rows = sc.nextInt();
14.
15. System.out.println("Here is your pattern....!!!");
16.
17. for (int i = 1; i <= rows; i++)
18. {
19. //Printing first half of the row
20.
21. for (int j = 1; j <= i; j++)
22. {
23. System.out.print(j+" ");
24. }
25.
26. //Printing second half of the row
27.
28. for (int j = i-1; j >= 1; j--)
29. {
30. System.out.print(j+" ");
31. }
32.
33. System.out.println();
34. }
35.
36. //Closing the resources
37.
38. sc.close();
39. }
40. }
Output :
Pattern 10 :
1
2 1
3 2 1
4 3 2 1
5 4 3 21
6 5 4 321
7 6 5 4321
Java Program :
import java.util.Scanner;
System.out.println();
}
sc.close();
}
}
Output :