File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why this result in a simple program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why this result in a simple program?" Watch "Why this result in a simple program?" New topic
Author

Why this result in a simple program?

Karthik Balasubramanian
Ranch Hand

Joined: Dec 13, 2002
Posts: 43
Hi all,
I am trying to compile this following program. It just gives me the output of
Total 0
I dont know why? Can some one explain?
public class Temp {
public static void main (String args[])
{
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j)
{
System.out.println(" i = " + i + " : j = " + j);
total =total+ i + j;
}
System.out.println("Total " +total);
}
}
Thanks
Karthik
Harry Kong
Ranch Hand

Joined: Dec 06, 2002
Posts: 41
Change total > 30 to total < 30.
Your condition is false to begin with so the for loo[ never runs.


SCJP 1.4
Karthik Balasubramanian
Ranch Hand

Joined: Dec 13, 2002
Posts: 43
oh...yeah!!!sorry...I did n't check that...
Thank you very much
Karthik
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why this result in a simple program?