2 回答
TA贡献1834条经验 获得超8个赞
稍微调整一下你的代码,它就是这样工作的......
public class NumbersFunctions {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double x, y, z;
System.out.println("Please input 3 numbers");
x = keyboard.nextDouble();
y = keyboard.nextDouble();
z = keyboard.nextDouble();
smallest(x, y, z);
}
public static void smallest(double x, double y, double z)
{
if(x < y && x < z){
System.out.println(x);
}else if(y < z){
System.out.println(y);
}
}
}
TA贡献1850条经验 获得超11个赞
这是正确的写法。一个类中有 2 个方法。main() 将调用 minimum() 方法。
import java.util.Scanner;
public class NumbersFunctions
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double x, y, z;
System.out.println("Please input 3 numbers");
x = keyboard.nextDouble();
y = keyboard.nextDouble();
z = keyboard.nextDouble();
smallest(x, y, z);
//System.out.println(smallest(x, y, z));
}
public static void smallest(double x, double y, double z)
// public Double smallest(double x, double y, double z)
{
if(x < y && x < z){
System.out.println(x);
//return(x);
}
else if(y < z){
System.out.println(y);
//return(y);
}
else {
System.out.println(z);
//return(z);
}
}
添加回答
举报