Why does this program show 0.0
?.
Below is my code:
class new1{
public static void main (String[]args){
int discount = 15;
float discount1 = 15/100;
System.out.println(discount1);
}
}
Why does this program show 0.0
?.
Below is my code:
class new1{
public static void main (String[]args){
int discount = 15;
float discount1 = 15/100;
System.out.println(discount1);
}
}
In line float discount1 = 15/100;
is evaluated using the integer division.
If you want to get expected result, you should write like this
float discount1 = 15.0/100;