+ 5
Yes, it is kind of mean is it not? š¤ It is not the floats and doubles, however, that do this, but them ints!
You see, dividing 10/100 is dividing two integers. The return type has nothing to do with it! And it so happens that 100 fits zero times into ten. Hence, 10/100 is zero. Whence your output.
+ 4
You divide 2 integers and assign it to double/float variables.
However the integer division is performed first (10/100 = 0) and then the result is casted to double/float (0.0).
In case you want to perform double/float division, cast at least one of the operands to double/float before performing division.
+ 3
You are still dividing integers.
If neither t nor h have to be int, then
float t = 10;
float h = 100;
Otherwise, cast explicitly as zemiak suggested.
+ 2
one number should be decimal
tnen it works correctly
double problem = (double) 10/100;
float problem2 = (float) 10/100;
+ 2
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner scanner =
new Scanner(System.in);
int amount = scanner.nextInt();
int t = 10;
int h = 100;
float per = (float) t/h;
float pay = per * amount;
System.out.println( pay);
}
}