【发布时间】:2023-04-03 05:40:01
【问题描述】:
我没有在 main 上初始化任何东西。我想要的只是调用一个外部方法。但是,当调用 picnicCost() 时,我不知道在括号内放什么,因为我没有在 main.js 中使用任何变量。
import java.util.*;
public class picnic
{
static Scanner scan=new Scanner(System.in);
public static void main(String args[])
{
picnicCost(0,0,0);
}
public static double flatFee(double a)
{
System.out.println("Enter the number of people attending: ");
a=scan.nextDouble();
return a*5.00;
}
public static double MealP(double b)
{
System.out.println("Enter the number of poeple purchasing a meal: ");
b=scan.nextDouble();
return b*2.75;
}
public static double iceCreamCost(double c)
{
System.out.println("Enter the number of poeple purchasing ice cream: ");
c=scan.nextDouble();
return c*.75;
}
public static double picnicCost(double a, double b, double c)
{
return flatFee(a) + MealP(b) + iceCreamCost(c);
}
}
【问题讨论】:
-
我没有使用任何变量然后做。
-
例如,您可以在主目录中添加:
double flatFee = flatFee();。并且不需要在 flatFee 方法中使用a参数。 -
看起来你的前三个方法中的任何一个都不需要参数。
-
使用变量,我想你会得到预期的结果。
-
看起来您的任何方法都不需要任何更改才能工作。预期的行为/输出是什么?
标签: java main-method