+ 1
How come the value of y is 70 i dint get it?
public class Program { public static void main(String[] args) { int x = 34; int y = x++ + ++x; System.out.println(x); System.out.println(y); } } O/p X 36 y 70
5 ответов
+ 4
here value of y by inclement becomes
x++ = 34
++x = 36
x++ + ++x = 34+36 = 70 .
And in this way it becomes 70
+ 4
no x++ becomes 35 when it is incremented one and called after incrementing it first .
Example :-
x = 10;
System.out.println(x++);
System.out.println(x);
The output will be ;
10
11
While in the case of prefix increment .
It will be like ;-
x = 10 ;
System.out.println(++x);
Here it will be 11;
+ 2
Thank you:)
- 1
But while learning it's written that x++ becomes 35
- 1
public class Program {
public static void main(String[] args) {
int x = 34;
int y = x++;
System.out.println(y);
System.out.println(x);
}
}
y=34
x=35
Check this op