I’m trying to print the largest number of 2 numbers using java Math but I keep getting an error. I’m new to Java and I would really appreciate the help.
Code:
public class Math { public static void main(String[] args) { System.out.println(Math.max(5, 10)); } }
Error:
Math.java:3: error: cannot find symbol System.out.println(Math.max(5, 10)); ^ symbol: method max(int,int) location: class Math 1 error
Advertisement
Answer
The problem is that you called your class Math
as well. The compiler wants to find the method max
in your own class.
To fix that, give your class another name.