+ 5
Could you please explain the output of two Java statements? Topic: operators
int a = 2; int b = 3; 1) --b == --a // output true 2) a == b ++ && b == 3 // output true Could you please also tell me whether there is such a rule in Java, which demands executing the operators coming with variables before those coming with numbers? Something like here: a + b/2 == 2 // output true
5 Respostas
+ 6
i got false for both of these ? how are you getting true?
+ 4
ZdzichPych
/*i ran this in code playground and both returned false*/
int a = 2; int b = 3;
boolean z = --b == --a;
boolean y = a == b ++ && b == 3;
System.out.print(z+" "+y);
+ 3
Well, it looks this way: the first statement is presumably true on both Eclipse and SoloLearn's Playground, whereas the second one is true only on Eclipse. Meanwhile, I also feel the output should be false for both cases :/
+ 2
Thank's for sharing your code, I write it without booleans, just: int a = 2; int b = 3; System.out.println(--b == --a);
System.out.println(a == b++ && b == 3);
+ 2
Hi! I tried to run what you did on code playground:
public class Program
{
public static void main(String[] args) {
int a = 2; int b = 3;
System.out.println(--b == --a);
System.out.println(a == b++ && b == 3);
}
}
And the output was
false
false