+ 4
Can someone explain what will be it's output and how?đ€
class Pattern { public static void main(String args[]) { int i,j; for(i=1;i<=4;i++) { for(j=4;j>=i;j--) { System.out.print("*"); } System.out.println (); } } }
2 Answers
+ 24
i=1 , j=4,3,2,1
i=2, j=4,3,2
i=3,j=4,3
i=4,j=4
//loop stops âș
//for each j , a * & for each i a line break
+ 9
Output:
****
***
**
*
Explanation:
Inner for loop prints 4,3,2,1 stars as variable i gets incremented in outer for loop.
Last line if outer for loop prints new line.
By the way, use code playground and you can check output yourself.