[英]Error in using the java Math class in an array
我正在嘗試使用 java Math 打印最大數量的 2 個數字,但我一直收到錯誤消息。 我是 Java 新手,非常感謝您的幫助。
代碼:
public class Math {
public static void main(String[] args) {
System.out.println(Math.max(5, 10));
}
}
錯誤:
Math.java:3: error: cannot find symbol
System.out.println(Math.max(5, 10));
^
symbol: method max(int,int)
location: class Math
1 error
問題是你也把你的班級稱為Math
。 編譯器希望在您自己的類中找到方法max
。
要解決這個問題,請為您的班級命名。
public class Math {
public static void main(String[] args) {
System.out.println(java.lang.Math.max(5, 10));
}
}
或者你可以導入類import java.lang.Math;
用java.lang.Math
替換Math
,這樣就可以了。
class Math {
public static void main(String[] args) {
System.out.println(java.lang.Math.max(5, 10));
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.