how to approach this
Inverted hour glass
@anmolsr755
Hello Anmol,
break each line into three parts
numbers then some spaces and then again numbers.
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.
import java.util.Scanner;
public class invertedhourglass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n =sc.nextInt();
int nst =1;
int nsp=2*n-1;
int nr=2*n+1;
int val1;
int val2;
//row
int row=1;
while( row<=nr)
{
val1=5;
val2=1;
for (int cst=1;cst<=nst;cst++){
if(cst<=nst){
System.out.print(val1-- + " ");
}
}
for (int csp=1;csp<=nsp;csp++){
System.out.print(" ");
}
int cst=1;
if (row==n+1){
cst=2;
}
for (;cst<=nst;cst++){
if(cst<=nst){
System.out.print(val2++ + " ");
}
}
System.out.println();
if(row<=nr/2){
nst=nst+1;
nsp=nsp-2;
}
else{
nst=nst-1;
nsp=nsp+2;
}
row=row+1;
}
}
}
This is my code and I am not getting how to insert value in second side of the pattern. Please check it and let me know