+ 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 (); } } }

31st Jan 2018, 3:32 PM
udisha khandelwal
udisha khandelwal - avatar
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
31st Jan 2018, 4:23 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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.
31st Jan 2018, 3:39 PM
DAB
DAB - avatar