java - 为什么不打印此代码?有什么错误?

标签 java compiler-errors return

为什么不打印此代码?我正在尝试编写一种名为min的方法,该方法需要3个参数并返回三个值中的最小值。

public class Practice {
    public static void main(String[] args){
        min(3, -2, 7);
        min(19, 27, 6);

    }

    public static void min(int number1, int number2, int number3){
        return Math.min(number1, Math.min(number2, number3));

        System.out.println();
    }
}

最佳答案

这甚至不会作为行编译

System.out.println(); is after `return` statement,hence it is unreachable

只需使用以下命令打印您要返回的值:
public class Practice {
    public static void main(String[] args){
       System.out.println( min(3, -2, 7));
       System.out.println(min(19, 27, 6));

    }

    public static int min(int number1, int number2, int number3){
        return Math.min(number1, Math.min(number2, number3));


    }
}

关于java - 为什么不打印此代码?有什么错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26094081/

相关文章:

java - 如何在POM中使用条件属性

Python - 从 Tkinter 回调返回

java - java中返回值的含义?

java - HttpClient,如何发送 URI 字符串中的非法字符

java - 如何在jdbc中使用setClob方法?

java - 如何在 hql/hibernate 中的值集中使用 equals?

vba - 输入框编译错误

c - 这是未定义的行为(使用字符串文字)

c - 为什么我会收到此错误和警告?错误和警告在描述中

javascript - 我不明白 javascript 中的函数返回