我已经编写了这段代码,但是,每次输入十进制值时,它都不起作用。即使输入十进制值,如何使此代码正常工作?例如,如果我输入一个值 7.5,它应该显示“运费为 9.45 美元”
import java.util.Scanner;
public class IfElse {
public static void main(String[] args) {
int marksObtained;
Scanner input = new Scanner(System.in);
System.out.println("Please enter a package weight in pounds:");
marksObtained = input.nextInt();
if (marksObtained>20)
{
System.out.println("The package is too heavy to be shipped");
}
else if (marksObtained>10)
{
System.out.println("The shipping cost is $12.50");
}
else if (marksObtained>3)
{
System.out.println("The shipping cost is $9.45");
}
else if (marksObtained>1)
{
System.out.println("The shipping cost is $4.95");
}
else if (marksObtained>0)
{
System.out.println("The shipping cost is $2.95");
}
else if (marksObtained<0)
{
System.out.println("The weight must be greater than zero");
}
}
}