Write a program that displays the following output:
**********
*********
********
*******
******
*****
****
***
**
*
is there a way to solve this with loops?
Printable View
Write a program that displays the following output:
**********
*********
********
*******
******
*****
****
***
**
*
is there a way to solve this with loops?
Yes, loops would be the way to solve it.
I agree, a for loop would work great. What have you tried and how does it work or not work?
is this optimalCode Java:public class Unit6_2 // Peter Krasinski { public static void main( String [] args ) { int x = 0; System.out.println(); while ( x <= 10 ) { switch ( x ) { case 0: System.out.println("**********"); break; case 1: System.out.println("*********"); break; case 2: System.out.println("********"); break; case 3: System.out.println("*******"); break; case 4: System.out.println("******"); break; case 5: System.out.println("*****"); break; case 6: System.out.println("****"); break; case 7: System.out.println("***"); break; case 8: System.out.println("**"); break; case 9: System.out.println("*"); break; case 10: System.out.println(" "); break; } x++; } } }public class Unit6_2 // Peter Krasinski { public static void main( String [] args ) { int x = 0; System.out.println(); while ( x <= 10 ) { switch ( x ) { case 0: System.out.println("**********"); break; case 1: System.out.println("*********"); break; case 2: System.out.println("********"); break; case 3: System.out.println("*******"); break; case 4: System.out.println("******"); break; case 5: System.out.println("*****"); break; case 6: System.out.println("****"); break; case 7: System.out.println("***"); break; case 8: System.out.println("**"); break; case 9: System.out.println("*"); break; case 10: System.out.println(" "); break; } x++; } } }
No, it is the worst way to do it.Quote:
is this optimal
What if the number of lines to print is gotten from the user?
You need a separate loop using the print() method to print single *s on a line. The number of *s to print being determined by what line you are printing one. The first line having the most and each line after that having one less.
got it thanks
nvm
please check the simple and easy code
//code removed
@javalion, welcome to the forums. Please read the forum rules and the following:
http://www.javaprogrammingforums.com...n-feeding.html
Your post has been edited.