File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Printing a string" Watch "Printing a string" New topic
Author

Printing a string

Paul Hobson
Greenhorn

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
Greenhorn

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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Printing a string
 
Similar Threads
2D graphic repaint() logic
Swing Printing problem
Java printing
Messagebox with Mouseevent
Print a JTextArea