Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing a string

 
Paul Hobson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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.
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
it prints a blank output
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it prints a blank output
Got some code where we could see System.out.println() and other relevant stuff?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic