Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

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

Anto Telvin
Ranch Hand
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
Ranch Hand
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
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
Posts: 5575
Hi Anto Telvin , you can edit your post by clicking your Edit/Delete icon

Anto Telvin
Ranch Hand
Posts: 113
thank you

Campbell Ritchie
Sheriff
Posts: 50687
83
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.