Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class demo01 { public static void main(String[] args){ for(int i=0; i<7;

ID: 3619044 • Letter: P

Question

public class demo01 { public static void main(String[] args){ for(int i=0; i<7; i++){ for(int j=0; j<5; j++) if (Math.abs(i-j)<=j) System.out.print('*');// i want toknow in detail how it is computed here else System.out.print('-'); System.out.println(); } } } public class demo01 { public static void main(String[] args){ for(int i=0; i<7; i++){ for(int j=0; j<5; j++) if (Math.abs(i-j)<=j) System.out.print('*');// i want toknow in detail how it is computed here else System.out.print('-'); System.out.println(); } } }

Explanation / Answer

public class demo01
{ public static void main(String[] args)
{
for(int i=0; i<7;i++)                  //this will print 7 lines
    {for(int j=0; j<5; j++)     //5 charactes per line             {//see trace below
   if(Math.abs(i-j)<=j)    
                        System.out.print('*');              else
      System.out.print('-');
             }
          System.out.println();       //end ofprinting the row, so go to the next row
      } } }