The output is taking count, name, income and then again income according to the number of counts and then shows outOfBound
error for the count.
Here is the code -
public class Main { // Tax Calculator App
public static long calculateTax(long income1){
long tax = 0;
if (income1 >= 300000) {
tax = income1 * 20 / 100;
} else if (income1 >= 100000 && income1 < 300000) {
tax = income1 * 10 / 100;
} else if (income1 < 100000) {
tax = 0;
System.out.println("Tax Amount = 0 ");
}
return tax;
}
public static void main(String[] args) {
System.out.println("Tax Calculator App");
System.out.println("-----WELCOME-----");
Scanner sc = new Scanner(System.in);
System.out.println("Enter total person count: ");
int count = sc.nextInt();
sc.nextLine();
String[] pName = new String[count];
long[] pIncome = new long[count];
System.out.println("Enter the name: ");
for (int i = 0; i <= count; i++) {
pName[i] = sc.nextLine();
System.out.println("Enter the income: ");
}for (int i = 0; i <= count; i++) {
pIncome[i] = sc.nextLong();
sc.nextLine();
long tax = 0;
System.out.println("Name: " + pName + "Tax: " + tax);
}
}
}