class W
{
public static void main(String[] args)
{
int i=0;
int j= i++ + test(i) + i;
System.out.println(i);
System.out.println(j);
}
static int test(int i)
{
return i++;
}
}
Am getting 1 and 2 as its output.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
class W
{
public static void main(String[] args)
{
int i=0;
int j= i++ + test(i) + i;
System.out.println(i);
System.out.println(j);
}
static int test(int i)
{
return i++;
}
}
Am getting 1 and 2 as its output.
There are two println statements. The first prints a 1 and the second prints a 2.
To see what the code is doing add some more println statements that print out the values of all variables before and after every statement where the variables values are changed.System.out.println("b i="+i); i = <code that changes i> System.out.println("a i="+i);
Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.
I want to know how exactly this increment operators are working in test method.
Did you do as I suggested and add println statements to print out the values of the variables so you can see what each statement is doing?
Also if you want to see how some operator works, write a short simple program that uses that operator and use println statements to print out the result so you can see what the operator does.
Also see the tutorial:
http://docs.oracle.com/javase/tutori...bolts/op1.html
If you don't understand my answer, don't ignore it, ask a question.
Ya i did try,but i dint get whats getting passed through test() method and its output from test method.
Please post the print outs and ask any questions about what a specific statement did that you do not understand.
Print out what is passed to test() and what is returned by test().whats getting passed through test() method and its output from test method.
Also try this to see how post++ works:int k = 0; System.out.println("k++="+k++); // k++=0 System.out.println("after k++ k="+k); // after k++ k=1
If you don't understand my answer, don't ignore it, ask a question.