Thursday, October 23, 2014



Building Java Programs A Back To Basics Approach - 3rd Edition
by Stuart Reges and Marty Stepp


Chapter 2 Exercise 9

Write nested for loops to produce the following output:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~
+~++~++~++~++~++~++~++~++~++~++~++~++~++~++~++~+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Copyright Mihai George Forlafu @ 2014
 * Copenhagen School of Design and Technology
 * Building Java Programs A Back To Basics Approach 5th edition
 * Chapter 2 Exercise 9, page 157
 */

package ch2_ex9;
public class Ch2_Ex9 
{
    public static void main(String[] args) 
    {
        grup1();
        grup2();
        grup3();
        grup1();
    } 
    
    public static void grup1()
    {
     for (int j = 4; j>=1; j--)
     {
       for (int i= 4; i>=1;i--)
        {
            System.out.print("~~~");
        }
     }
        System.out.println("");
    }
   
    public static void grup2()
    {
     for (int j = 4; j>=1; j--)
     {
       for (int i= 4; i>=1;i--)
        {
            System.out.print("~+~");
        }
     }
        System.out.println("");
    }
   
    public static void grup3()
    {
     for (int j = 4; j>=1; j--)
     {
       for (int i= 4; i>=1;i--)
        {
            System.out.print("+~+");
        }
     }
        System.out.println("");
    }
   
}

0 comments:

Post a Comment