pls improve my code and mark the improvements.
Hourglass pattern
Hey @Utkarshsingh5298291
There is no need to take the Val2 variable
correct code :
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int nst = 1;
int nr = 2 * n + 1;
int nsp = 2 * n - 1;
int nsp2 = 1;
int nst2 = 1;
// work
int row = 1;
while (row <= nr) {
int val = n;
int val2 = 1;
int cst = 1;
while (cst <= nst) {
System.out.print(val + " ");
cst++;
val--;
}
int csp = 1;
while (csp <= nsp) {
System.out.print(" ");
csp++;
}
cst = 1;
val++;
if(row==n+1) // n+1 th row me val ko val+2 kena h.
val++;
while (cst <= nst2) {
if(row==n+1 && nst2==cst) {// In N+1 th row me extra 1 element print kr raha tha usko roka gayah
break;
}
System.out.print(val + " ");
cst++;
val++;
}
// prep-----------------------------------------------------
if (row <= nr / 2) {
nst = nst + 1;
nst2 = nst2 + 1;
nsp = nsp - 2;
} else {
nst = nst - 1;
nst2 = nst2 - 1;
nsp = nsp + 2;
}
row++;
System.out.println();
}
}
}
bro can you help me out with this question -Increasing Decresing secquence-https://ide.codingblocks.com/s/290304