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

Why this result in a simple program?

 
Karthik Balasubramanian
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change total > 30 to total < 30.
Your condition is false to begin with so the for loo[ never runs.
 
Karthik Balasubramanian
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh...yeah!!!sorry...I did n't check that...
Thank you very much
Karthik
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic