Computer Science, asked by aditya4080, 1 year ago

Write a program in JAVA to print the following pattern:
1123
2234
3345
4456
I am not sure if the pattern is wrong....if so please make the required correction(s).
Please send ASAP

Answers

Answered by nhkmk786
1
import java.util.Scanner; public class Pattern20 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(k); } for (int l = i - 1; l >= 1; l--) { System.out.print(l); } System.out.println(); } } }
Similar questions