Write a Java program called Practice73 that uses nested loop

Write a Java program (called Practice_7_3) that uses nested loops to print out the following shape. See Lab 6 and chapter 4 slides for related examples.

Solution

The java program is as follows:

public class Square{  
public static void main(String[] args){
   int i,j,k;
   //applying loops for the printing of star
   //as we need 8 line we have compared values in the loops by 8
   for(i=1; i<=8; i++)
   {
       //loop i is for changing the line
       //loop j is for printing the space
   for(j=8; j>=i; j--)
   {
   System.out.print(\" \");
   }
   //loop k is for printing the required no of stars
   for(k=1; k<=(2*i-1); k++)
   {
   System.out.print(\"*\");
   }
   //println is applied because we want output in newline
   System.out.println(\"\");
   }
   }
}

 Write a Java program (called Practice_7_3) that uses nested loops to print out the following shape. See Lab 6 and chapter 4 slides for related examples. Soluti

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site