0
Why did i get 0 here as the output
public class Program { public static void main(String[] args){ System.out.println(9/10); } }
6 Answers
+ 4
Because 10 goes into 9 zero times. So the answer is 0.
+ 3
System.out.println(9.0/10)... Basically make one or both the inputs double data type
+ 1
how do i get 0.9
+ 1
at least one number should be of type double.ur code
public class Program{
public static void main(String[] args){
System.out.println(9/10.0);
}}
+ 1
public class Program {
public static void main(String[] args){
System.out.println(9/10);
System.out.println(9.0/10);
System.out.println(9/10.0);
}
}
:::: OUTPUT ::::
0
0.9
0.9
^That's implicit typecasting. When it sees that one of the values is a float or double, it assumes that you're implying both are of that type so it automatically converts it so you can do proper calculations with it.
0
if you put only normal numbers like 1,2,3 it gonna treat them as integers, if you want to show 0.9 see cyk answer.