• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anto Telvin , you can edit your post by clicking your Edit/Delete icon
 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic