Write a program that displays the following output:
**********
*********
********
*******
******
*****
****
***
**
*
is there a way to solve this with loops?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.
If you don't understand my answer, don't ignore it, ask a question.
I agree, a for loop would work great. What have you tried and how does it work or not work?
is this optimalpublic 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.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.
If you don't understand my answer, don't ignore it, ask a question.
got it thanks
nvm
please check the simple and easy code
//code removed
Last edited by copeg; January 3rd, 2013 at 12:39 AM. Reason: Removed spoonfed code
@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.