public static void main(String args [])
{
double dimes;
double quaters;
Scanner input = new Scanner(System.in);
System.out.print("Enter number of Dimes:");
dimes = input.nextDouble();
System.out.print("Enter Number of Quaters:");
quaters = input.nextDouble();
double dollars= dollar_amount(dimes,quaters);
System.out.println("Dollar Amount total: $" + dollars);
public static double dollar_amount(dimes,quaters);
dollars= dollar_amount(dimes,quaters);
System.out.println("Total dollar amount: $" + dollars);
}
double dollar_amount(double dimes, double quaters);
{
dollars = (0.10 * dimes)+(0.25 * quaters);
}
return dollars;
}
}
}
我有一个关于如何调用方法的问题。我遵循了我给出的提示,但不知怎的,我还没有开始调用方法。
提示:
答案 0 :(得分:0)
我认为你的方法体是错误的
Double dollar_amount(double dimes, double quaters);
{
Double dollars = (0.10 * dimes)+(0.25 * quaters);
return dollars;
}
你称之为正确的地方。没问题
答案 1 :(得分:0)
您正在尝试使用方法设置变量的值。您必须先正确定义方法dollar_amount(dimes,quaters)
,然后才能调用它。
将此代码粘贴到当前代码中,并粘贴到主类中。
public static void main(String args []){
double dimes;
double quaters;
Scanner input = new Scanner(System.in);
System.out.print("Enter number of Dimes:");
dimes = input.nextDouble();
System.out.print("Enter Number of Quaters:");
quaters = input.nextDouble();
double dollars= dollar_amount(dimes,quaters);
System.out.println("Dollar Amount total: $" + dollars);
}
public static double dollar_amount(dimes,quaters){
dollars = (0.10 * dimes)+(0.25 * quaters);
return dollars;
}
答案 2 :(得分:0)
你必须做一些改变,试试这样。
public static void main(String args[]) {
double dimes;
double quaters;
Scanner input = new Scanner(System.in);
System.out.print("Enter number of Dimes:");
dimes = input.nextDouble();
System.out.print("Enter Number of Quaters:");
quaters = input.nextDouble();
double dollars = dollar_amount(dimes, quaters);
System.out.println("Dollar Amount total: $" + dollars);
dollars = dollar_amount(dimes, quaters);
System.out.println("Total dollar amount: $" + dollars);
}
public static double dollar_amount(double dimes, double quaters) {
double dollars = (0.10 * dimes) + (0.25 * quaters);
return dollars;
}