我在java中编写了一个简单的程序:
public class Will {
int static square(int x) {
int y = x * x;
return y;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a number...");
int n = sc.nextInt();
int result = Will.square(n);
System.out.println("Square of " + n + " is " + result);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我收到了这些错误:
square.java:6: error: <identifier> expected
int static square (int x)
^
square.java:6: error: invalid method declaration; return type required
int static square (int x)
^
2 errors
Run Code Online (Sandbox Code Playgroud)
如何解决这些问题?