I can write code for Christmas Tree using for loop. Now, I want to write that code with while loop. I just can't figure out what I'm doing wrong.
public static void main(String[] args) {
int i = 0;
int j =0;
int k =0;
while(i<10){
while(j<10-i){
System.out.print(" ");
j++;
}
while(k<(2*i)+1){
System.out.print("*");
k++;
}
++i;
System.out.println("");
}
}
I expect the output of code to be like the christmas tree. But, the actual output is:
*
**
**
**
**
**
**
**
**
**