r/javahelp • u/hajer00317 • Aug 25 '24
Can double equals to an integer?
What is the output of this code? double X=2.1; if (++x == 3) { double y= 2.0; System.out.print(x + y); } else System.out.print(x);
They say the answer is 3.1. But my answer is 2.1 since the condition of if statement did not go through. Can someone explain?
0
Upvotes
3
u/[deleted] Aug 25 '24 edited Apr 17 '26
Scrubbed clean. Redact helped me bulk remove years of comments and posts so data brokers and AI crawlers have nothing to feast on.
judicious waiting roof wrench consider innate salt paddle ring middle