((10/5)+10 + " " + (10/3) + 2) output ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

((10/5)+10 + " " + (10/3) + 2) output ??

public class Program { public static void main(String[] args) { System.out.println((10/5)+10 + " " + (10/3) + 2); } } The output should be something like "12 5", but I am getting "12 32" Can someone explain what exactly happened ?

3rd Oct 2018, 3:54 AM
Kay Fine
Kay Fine - avatar
1 Answer
+ 3
If you do math operations in println, it's better to wrap the task in parentheses Because if you use String in println, each subsequent number not enclosed in parentheses is treated as a string public class Program { public static void main(String[] args) { System.out.println( ((10/5)+10) + " " + ((10/3) + 2)); } }
3rd Oct 2018, 4:54 AM
Daniel (kabura)
Daniel (kabura) - avatar