aspose file tools*
The moose likes Beginning Java and the fly likes can anybody tell how the counting in loop happens for   this program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can anybody tell how the counting in loop happens for   this program?" Watch "can anybody tell how the counting in loop happens for   this program?" New topic
Author

can anybody tell how the counting in loop happens for this program?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
hi all

public class c5 {
public static void main(String[] args) {
int x=2;
int y=3;
if((y==x++)|(x<++y))
{
System.out.println(x+""+y);
}
}
}

thanks


Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
nope the question is how the counting of x and y in condition of if is calculating .sorry for the other question
Matteo Di Furia
Ranch Hand

Joined: Jun 20, 2008
Posts: 102
x is incremented by 1 AFTER the first check (y==x), then y is increased by 1
BEFORE the second check (x<y).

The result is 34.

Edit to make it clear, these are the steps :

1) y == x ? false [y=3, x=2]
2) x++; [y=3, x=3]
3) y++; [y=4, x=3]
4) x < y ? true
[ October 22, 2008: Message edited by: Matteo Di Furia ]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi Anto Telvin , you can edit your post by clicking your Edit/Delete icon
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
thank you
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38353
    
  23
Originally posted by seetharaman venkatasamy:
Hi Anto Telvin , you can edit your post by clicking your Edit/Delete icon
Agree. You have been around long enough to know about the code button.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can anybody tell how the counting in loop happens for this program?