0

Why System.out.print(16.0/5); prints 3.2?

Why is the result of 16.0/5 -> 3.2?

8th Oct 2019, 5:00 PM
João Vitor
João Vitor - avatar
5 Respuestas
+ 4
If you want print 16.0/5 use quotation marks. System.out.println("16.0/5"); And if you want to know why the output is double and not int. It's because you used an operator(+, -, *, /) with an double, so Java used double here. 😉
8th Oct 2019, 5:19 PM
Stefanoo
Stefanoo - avatar
+ 3
Hm, because... it is? Maybe you should ask your maths teacher. ;-) (Or tell us what you *actually* want to know.)
8th Oct 2019, 5:04 PM
HonFu
HonFu - avatar
+ 1
João Vitor So according to you what should print here.
8th Oct 2019, 5:05 PM
A͢J
A͢J - avatar
+ 1
Stefanoo I think that he want to know why output is double. You explained well.
8th Oct 2019, 5:29 PM
A͢J
A͢J - avatar
+ 1
Yes, i ask because i didn't know that we could calculate double with int (i tought it must be same type). Thanks for the information! 👍
8th Oct 2019, 5:43 PM
João Vitor
João Vitor - avatar