0

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);
    }
}
paisanco
  • 4,032
  • 6
  • 29
  • 31
Weskr
  • 1
  • 1

1 Answers1

2

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;
John Joe
  • 11,400
  • 14
  • 56
  • 120