i want to that what i have used in my code is the right way to approach this type of problem or is there any other way in which i should have done this problem
Pattern triangle approach
how to share the code?
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
if(n>0&&n<10){
int row=1;
int nsp=n-1;
while(row<=n){
for(int i=0;i<nsp;i++){
System.out.print(" “);
}
for(int i=0;i<row;i++){
System.out.print(row+i+” ");
}
int xh=row+row-2;
for(int i=0;i<row-1;i++){
System.out.print(xh+" ");
xh--;
}
for(int i=0;i<nsp;i++){
System.out.print(" ");
}
System.out.println();
row++;
nsp--;
}
}
}
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.