-1

So im using the following code but when the time comes for the class to print the tax values they all come out as zero,can anyone tell me why?I have checked and the income values work as intended and are different than zero.

System.out.println("Enter number of clients");
n=scan.nextInt();
int[] income;
income=new int[n];
int i=0;
for(i=0;i<=(n-1);i++){
    System.out.print("Enter income for client no"+(i+1)+":\n");
    int a=scan.nextInt();
    income[i]=a;
}

float tax[ ];      
tax=new float[n];   
for(i=0;i<=(n-1);i++){
    if(income[i]<=0){
        tax[i]=0;
    }else if(income[i]<=10000){
        tax[i]=(income[i]*(9/100));
    }else if(income[i]<=20000){
        tax[i]=income[i]*(22/100);
    }else if(income[i]<=30000){
        tax[i]=income[i]*(28/100);
    }else if(income[i]<=40000){
        tax[i]=income[i]*(36/100);
    }else{
        tax[i]=income[i]*(44/100);
    }
}
Filip Halaxa
  • 588
  • 4
  • 12

1 Answers1

0

You should use double instead of float and use this notation when you do the division:

tax[i]= income[i] * (9.0 / 100.0);
Couper
  • 375
  • 4
  • 11