• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic