【发布时间】:2022-07-13 07:53:24
【问题描述】:
这是我大学班级的实验室之一,有了这个,我真的不知道该怎么做。这些是说明: 标准高中跑道的一圈正好是 0.25 英里。定义一个名为 lapsToMiles 的方法,该方法接受一个 double 作为参数,表示圈数,并返回一个表示英里数的 double。然后,编写一个以圈数为输入的主程序,调用方法 lapsToMiles() 计算里程数,并输出里程数。
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
System.out.printf("%.2f\n", yourValue);
Ex: If the input is:
7.6
the output is:
1.90
Ex: If the input is:
2.2
the output is:
0.55
The program must define and call a method:
public static double lapsToMiles(double userLaps)
这是我目前所拥有的: 导入 java.util.Scanner;
public class LabProgram {
public static double lapsToMiles(double userLaps) {
userLaps = userMiles/0.25;
return double userLaps;
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double userLaps = scnr.nextDouble();
userLaps.lapsToMiles();
System.out.printf("%.2f\n", lapsToMiles);
}
}
我一直遇到问题,不知道我是否设置正确。
【问题讨论】:
-
我也遇到了错误。比如这个:LabProgram.java:7: error: '.class' expected return double userLaps; ^ 1 个错误
标签: input methods return output calculation