Last active
October 16, 2017 16:36
-
-
Save julianjupiter/0436dbb66a9727c5a8b83e425bd2ad7f to your computer and use it in GitHub Desktop.
Triangle in Java 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 While { | |
public static void whileLoop1() { | |
int columnCounter = 5; | |
while (columnCounter >= 1) { | |
int rowCounter = 1; | |
int space = 5 - columnCounter; | |
while (space > 0) { | |
System.out.print(" "); | |
space--; | |
} | |
while (rowCounter <= columnCounter) { | |
System.out.print("*"); | |
rowCounter++; | |
} | |
System.out.println(); | |
columnCounter--; | |
} | |
} | |
public static void whileLoop2() { | |
int columnCounter = 1; | |
while (columnCounter <= 5) { | |
int rowCounter = 1; | |
while (rowCounter <= columnCounter) { | |
System.out.print("*"); | |
rowCounter++; | |
} | |
System.out.println(); | |
columnCounter++; | |
} | |
} | |
public static void whileLoop3() { | |
int columnCounter = 1; | |
while (columnCounter <= 5) { | |
int rowCounter = 5; | |
while (rowCounter >= columnCounter) { | |
System.out.print("*"); | |
rowCounter--; | |
} | |
System.out.println(); | |
columnCounter++; | |
} | |
} | |
public static void whileLoop4() { | |
int columnCounter = 1; | |
while (columnCounter <= 5) { | |
int rowCounter = 1; | |
int space = 5 - columnCounter; | |
while (space > 0) { | |
System.out.print(" "); | |
space--; | |
} | |
while (rowCounter <= columnCounter) { | |
System.out.print("*"); | |
rowCounter++; | |
} | |
System.out.println(); | |
columnCounter++; | |
} | |
} | |
public static void main(String[] args) { | |
whileLoop1(); | |
System.out.println(); | |
whileLoop2(); | |
System.out.println(); | |
whileLoop3(); | |
System.out.println(); | |
whileLoop4(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment