• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

increment operators

 
Nithya Subramanian
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

In the following example they have used something like "i+++".
But i am unable to get it.
Can anyone help me to understand this.

Example:
public class Question21 {
public static void main(String[] args) {
int i=3;
System.out.println(getBoolean()? i=2*i++:i+++ ++i);
}
//Heads or tail?
public static boolean getBoolean(){
if((int)(Math.random()*2)==0)
return false;
else
return true;
}
}
 
sumi rankan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nithya Subramanian:
Hi All

In the following example they have used something like "i+++".
But i am unable to get it.
Can anyone help me to understand this.

Example:
public class Question21 {
public static void main(String[] args) {
int i=3;
System.out.println(getBoolean()? i=2*i++:i+++ ++i);
}
//Heads or tail?
public static boolean getBoolean(){
if((int)(Math.random()*2)==0)
return false;
else
return true;
}
}




I think if the condition is true it will return (2 * i++),else it returns(i++ + ++i)
 
Nithya Subramanian
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sumi rankan:




I think if the condition is true it will return (2 * i++),else it returns(i++ + ++i)


Yes you are correct. Thanks for your response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic