【发布时间】:2015-08-12 20:51:17
【问题描述】:
我不断得到一个';'预计在 checkBinary(String num) { ^ 错误中,但我找不到“;”的任何地方。我只学了几天java,所以问题可能很明显,我还没有学过。请提供详细的解释,以便我可以使用它来防止以后项目中出现问题。提前谢谢!
import java.io.*;
import java.util.Scanner;
public class checkbinary
{
public static void main(String[] args)
{
String num;
System.out.println("Enter a number:");
Scanner sc = new Scanner(System.in);
num = sc.nextLine();
if(checkBinary(num)) {
System.out.println("The number is: Binary");
} else {
System.out.println("The number is: Not Binary");
}
boolean checkBinary(String num) {
for(i=0;i<num.length();i++) {
digit = Integer.parseInt(num.substring(i,i+1));
if(digit > 1) {
return false;
}
}
return true;
}
}
【问题讨论】:
-
方法内的方法不允许
标签: java compiler-errors