错误 Java 扫描仪无法转换为双精度
Error Java Scanner cannot be converted to double
它在函数调用时显示错误,说不能将扫描器更改为双
import java.util.Scanner;
public class Main{
public static double calculateGrossIncome(double hrsPerWeek, double hrlyPay){
double weeklyPay = hrsPerWeek * hrlyPay;
double result = weeklyPay * 52;
return result;
}
public static void main(String[] args)
{
System.out.println("Enter HOurly Pay :");
Scanner hrlyPay = new Scanner(System.in);
hrlyPay.nextDouble();
System.out.println("Enter Hours Per week :");
Scanner hrsPerWeek = new Scanner(System.in);
hrsPerWeek.nextDouble();
double income = calculateGrossIncome( hrsPerWeek, hrlyPay);
System.out.println("The employee toatl gross income is " + income);
}
}
你只需要一个扫描仪实例,你应该将用户输入保存到一个变量中。
public static void main(String[] args)
{
System.out.println("Enter HOurly Pay :");
Scanner scanner = new Scanner(System.in);
double hrlyPay = scanner.nextDouble();
System.out.println("Enter Hours Per week :");
double hrsPerWeek = scanner.nextDouble();
double income = calculateGrossIncome( hrsPerWeek, hrlyPay);
System.out.println("The employee toatl gross income is " + income);
}
它在函数调用时显示错误,说不能将扫描器更改为双
import java.util.Scanner;
public class Main{
public static double calculateGrossIncome(double hrsPerWeek, double hrlyPay){
double weeklyPay = hrsPerWeek * hrlyPay;
double result = weeklyPay * 52;
return result;
}
public static void main(String[] args)
{
System.out.println("Enter HOurly Pay :");
Scanner hrlyPay = new Scanner(System.in);
hrlyPay.nextDouble();
System.out.println("Enter Hours Per week :");
Scanner hrsPerWeek = new Scanner(System.in);
hrsPerWeek.nextDouble();
double income = calculateGrossIncome( hrsPerWeek, hrlyPay);
System.out.println("The employee toatl gross income is " + income);
}
}
你只需要一个扫描仪实例,你应该将用户输入保存到一个变量中。
public static void main(String[] args)
{
System.out.println("Enter HOurly Pay :");
Scanner scanner = new Scanner(System.in);
double hrlyPay = scanner.nextDouble();
System.out.println("Enter Hours Per week :");
double hrsPerWeek = scanner.nextDouble();
double income = calculateGrossIncome( hrsPerWeek, hrlyPay);
System.out.println("The employee toatl gross income is " + income);
}