print the above pattern using Java programming
Answers
Answer: The required Java program is :-
public class Main {
public static void main(String[] args) {
int i,j;
for(i=1;i<=4;i++) {
for (j=1;j<=4-i;j++) {
System.out.print(" ");
}
for(j=1;j<=i;j++) {
System.out.print(j);
}
for(j=i-1;j>=1;j--) {
System.out.print(j);
}
System.out.println();
}
for(i=3;i>=1;i--) {
for(j=1;j<=4-i;j++) {
System.out.print(" ");
}
for(j=1;j<=i;j++) {
System.out.print(j);
}
for(j=i-1;j>=1;j--) {
System.out.print(j);
}
System.out.println();
}
}
}
Note :-
The above program is saved in a file named Main.java
Also, try-catch block can be used to avoid errors.