6 – Nesting (Level 5)

Sample Code

 Squares

public class Triangle
{
    public static void main (String args [])
    {
        for(int i=0;i<5;i++)
        {
            for (int j = 0; j<i; j++)
                   {
                   System.out.print("*");
                   }
            System.out.println("");
        }
    }
}

Table Square

public class nest1
{
    public static void main (String args [])
    {
        for(int i = 1; i<4; i++)
        {
        for(int j = 1; j<4; j++)
        {
            System.out.println(i + " x " + j + " = " + i*j );
        }
        }
    }
}

Exercise

  1. Print out the following shapes: \/ \/\/ \/\/\/ \/\/\/\/ \/\/\/\/\/
  2. Print out the following 54321 4321 321 21 1
  3. Print out the following shapes \*/ \**/ \***/ \****/ \*****/
  4. Print out a 10 x 10 table square
  5. Print out the following shapes \/ \\// \\\/// \\\\//// \\\\\/////
  6. Print out an 8 x 8 chessboard. Use * for black and – for white
  7. Print out the following shapes:
*
**
**
***
***
***
****
****
****
****
*****
*****
*****
*****
*****

Leave a Reply

Your email address will not be published. Required fields are marked *