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
  • 3,834
  • 6
  • 26
  • 31
iSee
  • 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
  • 10,340
  • 9
  • 48
  • 104