• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing a string

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int o = N%10;
if (o == 0)
G2 = "++";
else if (o <=9)
G2 = "+";
else if (o <= 6)
G2 = " ";
else if (o <= 2)
G2 = "-";
When i try to print this.. it won't print G2. G2 is a string.
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


... it won't print G2.


Do you get an exception? A blank output? A compile error? What do you mean by "it won't print G2"?
If you look at the logic a bit, by using the mod (remainder) operator the value of "o" will always be between 0 and 9. If it's zero, the first IF statement will handle it. If it's anything else then the second IF statement (0 <= 9) will evaluate to TRUE and so G2 will always be set to "+" for any digit 1-9. G2 will never be " " or "-". You might want to change the order of your IF clauses ...
 
Paul Hobson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it prints a blank output
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it prints a blank output
Got some code where we could see System.out.println() and other relevant stuff?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic