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 Answers
+ 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