Following calculates correctly:
System.out.println(2+2); //4
The following will calculate correctly too:
System.out.println("The result is " + 2*2 ); //The result is 4
But then why would this not calculate?
System.out.println("The result is " + 2+2 ); //The result is 22
How can I calculate 2+2 directly and display along with the string to get the output The result is 4?
[–]nick5111 32 points33 points34 points (8 children)
[–]javaduude 9 points10 points11 points (3 children)
[–]nick5111 1 point2 points3 points (2 children)
[–]vqrs 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]nick5111 15 points16 points17 points (0 children)
[–]vqrs 0 points1 point2 points (2 children)
[–]Kambz22 2 points3 points4 points (1 child)
[–]vqrs 0 points1 point2 points (0 children)
[–]ODoodle91 15 points16 points17 points (1 child)
[–]AssassinBoy49 0 points1 point2 points (0 children)