In java int /int is always an int how can i get a double value when input2 int value example if i enter 1/2 i will get 0.5 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In java int /int is always an int how can i get a double value when input2 int value example if i enter 1/2 i will get 0.5

can i get a doble value while i input 2 int like 1/20 is 0.5 if yes them how.

4th Feb 2018, 2:31 PM
rohit
1 Answer
+ 5
Just cast either the numerator or the denominator to double. System.out.print((double)1/20); Another way, System.out.print(1/20.0);
4th Feb 2018, 2:34 PM
Dev
Dev - avatar