Last active
October 17, 2017 02:53
-
-
Save julianjupiter/a6bc957f6737a0f10488878832387bfe to your computer and use it in GitHub Desktop.
Triangle in Java Do While
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
public class DoWhile { | |
public static void doWhileLoop1() { | |
int columnCounter = 5; | |
do { | |
int rowCounter = 1; | |
int space = 5 - columnCounter; | |
do { | |
System.out.print(" "); | |
space--; | |
} while (space > 0); | |
do { | |
System.out.print("*"); | |
rowCounter++; | |
} while (rowCounter <= columnCounter); | |
System.out.println(); | |
columnCounter--; | |
} while (columnCounter >= 1); | |
} | |
public static void doWhileLoop2() { | |
int columnCounter = 1; | |
do { | |
int rowCounter = 1; | |
do { | |
System.out.print("*"); | |
rowCounter++; | |
} while (rowCounter <= columnCounter); | |
System.out.println(); | |
columnCounter++; | |
} while (columnCounter <= 5); | |
} | |
public static void doWhileLoop3() { | |
int columnCounter = 1; | |
do { | |
int rowCounter = 5; | |
do { | |
System.out.print("*"); | |
rowCounter--; | |
} while (rowCounter >= columnCounter); | |
System.out.println(); | |
columnCounter++; | |
} while (columnCounter <= 5); | |
} | |
public static void doWhileLoop4() { | |
int columnCounter = 1; | |
do { | |
int rowCounter = 1; | |
int space = 5 - columnCounter; | |
do { | |
System.out.print(" "); | |
space--; | |
} while (space > 0); | |
do { | |
System.out.print("*"); | |
rowCounter++; | |
} while (rowCounter <= columnCounter); | |
System.out.println(); | |
columnCounter++; | |
} while (columnCounter <= 5); | |
} | |
public static void main(String[] args) { | |
doWhileLoop1(); | |
System.out.println(); | |
doWhileLoop2(); | |
System.out.println(); | |
doWhileLoop3(); | |
System.out.println(); | |
doWhileLoop4(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment