• Post Reply Bookmark Topic Watch Topic
  • New Topic

output of a staircase  RSS feed

 
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

New to programming, please see my code



code compiled with output below -

Enter number from 1 to 8:4
*
**
***
****
Enter number from 1 to 8:

and

Enter number from 1 to 8:9
*
**
***
****
*****
******
*******
********
*********
Enter number from 1 to 8:

the staircase looks good,however I want to remove the last line and if user chooses 9 i want them to get message "enter number from 1 to 8" and do not print out the staircase.

what am i doing wrong?
any help would be appreciated.

 
Greenhorn
Posts: 29
IntelliJ IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Test the input value (x <= 0 && x > 9) before the for loops
 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot.

I got it to work.
 
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sveto Koychev wrote: . . . (x <= 0 && x > 9) . . .
…and go through that boolean expression carefully before use, and check what values you get

Please avoid 1‑letter names for variables, except as in these suggestions.
Please get yourself a decent text editor and follow the suggestions in this thread. Find the link about writing backwards.

Your indentation is inconsistent and your //end comments are incorrect. There is a risk of your failing to match {s and }s. You can cause serious errors by incorrect indentation or formatting, so please have a look at these suggestions. “Writing backwards” makes it easier to avoid such errors.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!