Last active
December 15, 2015 00:18
-
-
Save JoelQFernandez/5171418 to your computer and use it in GitHub Desktop.
// Textbook: Java Programming (6th Edition) - Joyce Farrell
// Chapter 6: Looping
// Description: Java exercise in creating shapes and formatting numbers through the use of nested For Loops.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Filename: shapesNestedForLoops | |
// 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 For Loops. | |
public class shapesNestedForLoops | |
{ | |
public static void main(String[] args) | |
{ | |
shape1(); | |
shape2(); | |
shape3(); | |
shape4(); | |
shape5(); | |
shape6(); | |
shape7(); | |
} | |
/****************************************************************************** | |
* * | |
* ** | |
* *** | |
* **** | |
* ***** | |
******************************************************************************/ | |
public static void shape1() | |
{ | |
System.out.print("Shape 1 \n\n"); | |
for (int row=1; row<=5; row++) | |
{ | |
for (int column=1; column<=row; column++) | |
System.out.print('*'); | |
System.out.println(); | |
} | |
System.out.println(); | |
} // End Of Method | |
/****************************************************************************** | |
* ***** | |
* **** | |
* *** | |
* ** | |
* * | |
******************************************************************************/ | |
public static void shape2() | |
{ | |
System.out.print("Shape 2 \n\n"); | |
for (int row=1; row<=5; row++) | |
{ | |
for (int column=5; column>=row; column--) | |
System.out.print('*'); | |
System.out.println(); | |
} | |
System.out.println(); | |
} // End Of Method | |
/****************************************************************************** | |
* 1 | |
* 12 | |
* 123 | |
* 1234 | |
* 12345 | |
******************************************************************************/ | |
public static void shape3() | |
{ | |
System.out.print("Shape 3 \n\n"); | |
for (int row=1; row<=5; row++) | |
{ | |
for (int column=1; column<=row; column++) | |
System.out.print(column); | |
System.out.println(); | |
} | |
System.out.println(); | |
} // End Of Method | |
/****************************************************************************** | |
* 54321 | |
* 4321 | |
* 321 | |
* 21 | |
* 1 | |
******************************************************************************/ | |
public static void shape4() | |
{ | |
System.out.print("Shape 4 \n\n"); | |
for (int row=5; row>=1; row--) | |
{ | |
for (int column=row; column>=1; column--) | |
System.out.print(column); | |
System.out.println(); | |
} | |
System.out.println(); | |
} // End Of Method | |
/****************************************************************************** | |
* 1 | |
* 22 | |
* 333 | |
* 4444 | |
* 55555 | |
* 666666 | |
******************************************************************************/ | |
public static void shape5() | |
{ | |
System.out.print("Shape 5 \n\n"); | |
for (int row=1; row<=6; row++) | |
{ | |
for (int column=1; column<=row; column++) | |
System.out.print(row); | |
System.out.println(); | |
} | |
System.out.println(); | |
} // End Of Method | |
/****************************************************************************** | |
* * | |
* *** | |
* ***** | |
* ******* | |
* ********* | |
******************************************************************************/ | |
public static void shape6() | |
{ | |
System.out.print("Shape 6 \n\n"); | |
int row,column; | |
for ( row=1; row<=6; row++) | |
{ | |
for ( column=1; column<=row; column++ ) | |
{ | |
System.out.print('*'); | |
if ( column > 1 ) | |
System.out.print('*'); | |
} | |
System.out.println(); | |
} | |
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() | |
{ | |
System.out.print("Shape 7 \n\n"); | |
for ( int row=1; row<=6; row++) | |
{ | |
for (int column=row; column<=6; column++) | |
//for (int column=1; column<=row; column++) | |
{ | |
System.out.print(column + " "); | |
} | |
System.out.println(); | |
} | |
System.out.println(); | |
} // End Of Method | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment