made a short java program in Bluej upon compiling it and trying to get it to run it, it hangs with no output.
I’ve had this issue before when using the in.next function.
Regards for any help and my apologies for what may seem a simple question.
import java.util.Scanner;
public class net_salary{
public static void main(String[]args){
Scanner in = new Scanner(System.in);
float income;
float incometax;
float afterincometax;
float nationalinsurance;
float afterni;
float pension;
float netincome;
income = in.nextFloat();
if(income <9000)
{
incometax = 0;
afterincometax = income - incometax;
}
else if (income >=9000 && income <=21000)
{
incometax = (income * 0.15F);
afterincometax = income - incometax;
}
else if (income >=21000 && income<=31000)
{
incometax = income * 0.2F;
afterincometax = income - incometax;
}
else if (income >=31000 && income<=50000)
{
incometax = income * 0.225F;
afterincometax = income - incometax;
}
else
{
incometax = income * 0.25F;
afterincometax = income - incometax;
}
if(income < 16000)
{
nationalinsurance = 0;
afterni = income - nationalinsurance;
}
else if(income >= 16000 && income <= 31000)
{
nationalinsurance = income*0.05F;
afterni = income - nationalinsurance;
}
else if(income > 31000 && income <=40000)
{
nationalinsurance = income*0.09F;
afterni = income - nationalinsurance;
}
else
{
nationalinsurance = income*0.11F;
afterni = income - nationalinsurance;
}
pension = income *0.05F;
netincome = ((income - pension)-nationalinsurance)-incometax;
System.out.println("Your gross income is : £" + income) ;
System.out.println("Your income tax is : £" + incometax) ;
System.out.println("Your nationalinsurance £" + nationalinsurance) ;
System.out.println("Your pension is : £" + pension) ;
System.out.println("Your net income is : £" + netincome) ;
}
}
I’m not sure what the issue you are having is. When I run it, it works just fine. It took me a second to realize that it was waiting for user input, but once I figured that out I just typed in a number, hit enter, and it worked. If I were you I would add a prompt to the user, something like: