Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

output of a staircase

 
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Test the input value (x <= 0 && x > 9) before the for loops
 
Carolin Sha
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot.

I got it to work.
 
Marshal
Posts: 75642
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic