In: Computer Science
need to output this in java
Enter an integer: 5
1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
4 4 4 4 4 4 4
3 3 3 3 3
2 2 2
1
(in the shape of a diamond)
please help me with the correct code, thanks
import java.util.Scanner; public class PrintDiamond { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter an integer:"); int n = in.nextInt(); for (int i = 0; i < n; i++) { for (int j = 0; j < n-i-1; j++) { System.out.print(" "); } for (int j = 0; j < 2*i+1; j++) { System.out.printf("%-2d", i+1); } System.out.println(); } for (int i = n-2; i >= 0; i--) { for (int j = 0; j < n-i-1; j++) { System.out.print(" "); } for (int j = 0; j < 2*i+1; j++) { System.out.printf("%-2d", i+1); } System.out.println(); } } }