Please tell my mistake
@kasturichakraborty36_24075fa79f00d4e8 your while loop body doesn’t contain any operations bcoz your while loop starts at line no.17 and while loop ending bracket is at line no. 19 so add all the functioning in your while not outside of it.
PS : whenever you send a code copy paste the code in your doubt instead of an Image.
package Lecture1;
import java.util.Scanner;
public class Pattern13 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in) ;
int n = scn.nextInt() ;
int nr = 2*n-1;
int nst = 1;
//row
int row = 1;
while(row <=nr) {
//work
int cst = 1;
while(cst<= nst) {
System.out.print("*");
cst++;
}
}
// preparation
System.out.println();
if(row <= nr/2) {
nst = nst+1;
} else {
nst = nst-1;
}
row= row+1;
}
}
please correct my code now
@kasturichakraborty36_24075fa79f00d4e8 here is the corrected code :
package Lecture1;
import java.util.Scanner;
public class Pattern13 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in) ;
int n = scn.nextInt() ;
int nr = 2*n-1;
int nst = 1;
//row
int row = 1;
while(row <=nr) {
//work
int cst = 1;
while(cst<= nst) {
System.out.print("* ");
cst++;
}
// preparation
System.out.println();
if(row <= nr/2) {
nst = nst+1;
} else {
nst = nst-1;
}
row= row+1;
}
}
}
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.