My questions follow like this, there is an N number of people. considering N=9, I have to find Taxable income of those people. I've done the math for 1 employee but, applying it for other 8 people is too much of repeated code. Can I put IF statements inside a FOR loop? I've tried this but it shows an error at FOR-loop(i.e, variable N is already defined in method main(String[]))
public class IncomeTax {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int i,Tax = 0,N = 1;
System.out.print("Enter the Taxable Income of the Employee " +N+":");
i = input.nextInt();
for( int N=1 ;N<=9 ; N++ ){
if( i >= 0 & i<18200)
Tax = 0;
if( i >= 18201 & i<37000)
Tax = (int) (( i - 18200) * 0.19);
if( i >= 37001 & i<87000)
Tax = (int) ((( i - 37000) * 0.325)+3572);
if( i >= 87001 & i<180000)
Tax = (int) ((( i - 18200) * 0.37)+19822);
if( i >= 180001 )
Tax = (int) ((( i - 18200) * 0.45)+54097);
System.out.println("The Income Tax for the employee "+N+" is " + Tax);
}
}
}
The output should be of N=9, number of employees and their taxes respectively in order. Enter the Taxable Income of the Employee 1: The Income Tax for employee 1: Enter the Taxable Income of the Employee 2: The Income Tax for employee 2 : Enter the Taxable Income of the Employee 3: The Income Tax for employee 3: