Ques 8:
n = 5
-
*
-
-
*
i am not able to guess the logic how to build this pattern.
Ques 8:
n = 5
*
*
i am not able to guess the logic how to build this pattern.
Hii nipun,
In this pattern consider a matrix of n * n, you just need to print star at two diagonals of the matrix and at other positions just print spaces.
this is my code, and result is correct but,
Scanner s = new Scanner(System.in);
int n = s.nextInt();
// row
int row = 1;
// work
int nst = n;
while (row <= n) {
int cst = 1;
while (cst <= nst) {
if(row==cst || row+cst==n+1){
System.out.print("* ");
}
else{
System.out.print("- ");
}
cst++;
}
//preparation
System.out.println();
row++;
}
when i do not write the else statement then this code does not work…even when the conditions are correct
and my code for n=8 print this pattern with 4 " * " in the middle is it correct
Hi Nipun
Please send the link to your code along with the link to the question too. It will be easier for us to debug it and tell your mistake.