wood burning stoves
The moose likes Beginning Java and the fly likes Printing a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Printing a string" Watch "Printing a string" New topic

Printing a string

Paul Hobson

Joined: Oct 29, 2003
Posts: 4
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

Joined: Sep 03, 2003
Posts: 399

... 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

Joined: Oct 29, 2003
Posts: 4
it prints a blank output
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
it prints a blank output
Got some code where we could see System.out.println() and other relevant stuff?
I agree. Here's the link: http://aspose.com/file-tools
subject: Printing a string
It's not a secret anymore!