Skip to content

Instantly share code, notes, and snippets.

@JoelQFernandez
Last active December 15, 2015 00:09
Show Gist options
  • Save JoelQFernandez/5171303 to your computer and use it in GitHub Desktop.
Save JoelQFernandez/5171303 to your computer and use it in GitHub Desktop.
Java Programming (6th Edition) - Joyce Farrell Chapter 6 Looping Java exercise in creating shapes and formatting numbers through the use of nested for loops.
// Filename: shapesNestedWhileLoops
// Author: Joel Fernandez
// Date: 03.15.13
// Textbook: Java Programming (6th Edition) - Joyce Farrell
// Chapter 6: Looping
// Description: Java exercise in creating shapes and formatting numbers through the use
// of nested While loops.
public class shapesNestedWhileLoops
{
public static void main(String[] args)
{
shape1();
shape2();
shape3();
shape4();
shape5();
shape6();
shape7();
}
/******************************************************************************
* *
* **
* ***
* ****
* *****
******************************************************************************/
public static void shape1()
{
int row, column;
row = 1;
System.out.print("Shape 1 \n\n");
while (row <= 5)
{
column = 1;
while( column <= row)
{
System.out.print('*');
column = column+1;
}
System.out.println();
row = row+1;
}
System.out.println();
} // End Of Method
/******************************************************************************
* *****
* ****
* ***
* **
* *
******************************************************************************/
public static void shape2()
{
int row, column;
row = 5;
System.out.print("Shape 2 \n\n");
while (row > 0)
{
column = 1;
while( column <= row)
{
System.out.print('*');
column = column+1;
}
System.out.println();
row = row-1;
}
System.out.println();
} // End Of Method
/******************************************************************************
* 1
* 12
* 123
* 1234
* 12345
******************************************************************************/
public static void shape3()
{
int row, column;
row = 1;
System.out.print("Shape 3 \n\n");
while (row <= 5)
{
column = 1;
while( column <= row)
{
System.out.print(column);
column = column+1;
}
System.out.println();
row = row+1;
}
System.out.println();
} // End Of Method
/******************************************************************************
* 54321
* 4321
* 321
* 21
* 1
******************************************************************************/
public static void shape4()
{
int row, column;
row = 0;
System.out.print("Shape 4 \n\n");
while (row < 5)
{
column = 5;
while( column > row)
{
System.out.print(column-row);
column = column-1;
}
System.out.println();
row = row+1;
}
System.out.println();
} // End Of Method
/******************************************************************************
* 1
* 22
* 333
* 4444
* 55555
* 666666
******************************************************************************/
public static void shape5()
{
int row, column;
row = 1;
System.out.print("Shape 5 \n\n");
while (row <= 6)
{
column = 1;
while( column <= row)
{
System.out.print(row);
column = column+1;
}
System.out.println();
row = row+1;
}
System.out.println();
} // End Of Method
/******************************************************************************
* *
* **
* ***
* ****
* *****
******************************************************************************/
public static void shape6()
{
int row, column;
row = 1;
System.out.print("Shape 6 \n\n");
while (row <= 11)
{
column = 1;
while( column <= row)
{
System.out.print('*');
column = column+1;
}
System.out.println();
row = row+2;
}
System.out.println();
} // End Of Method
/******************************************************************************
* 1 2 3 4 5 6
* 2 3 4 5 6
* 3 4 5 6
* 4 5 6
* 5 6
* 6
******************************************************************************/
public static void shape7()
{
int row, column;
row = 1;
System.out.print("Shape 7 \n\n");
while (row <= 6)
{
column = row;
while( column <= 6)
{
System.out.print(column + " ");
column = column+1;
}
System.out.println();
row = row+1;
}
System.out.println();
} // End Of Method
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment