Java
Draw something pretty using ASCII art, subject to a few constraints. Please feel free to use your imagination as much (or as little) as you like.
JAVA PROGRAM:
/*Draw something pretty using ASCII art, subject to a few constraints. Please feel free to use your imagination as much (or as little) as you like.*/
//it has 4 nested loops and 2 nested nested loops
public class test {
public static void main(String[] args) {
int oddNumbersCounter = 1;
for (int row = 1; row < 6 ; row++) {
for (int dashes = 6 - row; dashes > 0; dashes--) {
System.out.print("-");
}
for (int oddNumbers = oddNumbersCounter; oddNumbers <= row;
oddNumbers++) {
int output = oddNumbers * 2 - 1;
for (int i = 0; i < oddNumbers; i++) {
System.out.print(output);
}
}
for (int oddNumbers = oddNumbersCounter; oddNumbers <= row;
oddNumbers++) {
int output = oddNumbers * 2 - 1;
for (int i = 0; i < oddNumbers - 1; i++) {
System.out.print(output);
}
}
for (int dashes = 6 - row ; dashes > 0; dashes--) {
System.out.print("-");
}
System.out.println();
oddNumbersCounter++;
}
}
}
OUTPUT :
-----1----- ----333---- ---55555--- --7777777-- -999999999-
Get Answers For Free
Most questions answered within 1 hours.