在编译它时在Bluej中编写了一个简短的java程序并尝试让它运行它,它没有输出就挂起了。 我在使用in.next函数之前遇到过这个问题。 关心任何帮助,并为看似简单的问题道歉。
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) ;
}
}
答案 0 :(得分:1)
它要求float
值并等待您输入一个值。
尝试添加:
System.out.println("Enter a value:");
就在此之前
income = in.nextFloat();
使这一事实更加明显。
然后输入一个浮动值,如5
,然后按“Enter”。
答案 1 :(得分:1)
在阅读标准输入之前你没有提示任何东西,所以只需输入一个数字然后点击返回即可运行。
答案 2 :(得分:1)
我不确定你遇到的问题是什么。当我运行它,它工作得很好。我花了一秒钟才意识到它正在等待用户输入,但是一旦我想出来,我只输入一个数字,点击输入,它就可以了。如果我是你,我会向用户添加提示,例如:
System.out.println("Please enter your income: ");
income = in.nextFloat();