Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
1.java';)';预期错误+;2. ';其他';没有';如果';错误_Java_If Statement_Compiler Errors_Compareto - Fatal编程技术网

1.java';)';预期错误+;2. ';其他';没有';如果';错误

1.java';)';预期错误+;2. ';其他';没有';如果';错误,java,if-statement,compiler-errors,compareto,Java,If Statement,Compiler Errors,Compareto,第8行遇到预期的错误);在第9行中发现了不带“if”的错误“else”。 这只是方法的一部分。开头声明了所有需要的变量(name1、name2、count),并说明了读取文件时可能出现的异常。此时,程序应该已经在读取文件,以便比较文件中写入的名称 while ( ! TextIO.eof() ) do { name1.compareTo(name2); if (name1.equals(name2));

第8行遇到预期的错误);在第9行中发现了不带“if”的错误“else”。 这只是方法的一部分。开头声明了所有需要的变量(name1、name2、count),并说明了读取文件时可能出现的异常。此时,程序应该已经在读取文件,以便比较文件中写入的名称

 while ( ! TextIO.eof() )
            do {
                name1.compareTo(name2);
                if (name1.equals(name2));
                count++;
            } while ( ! TextIO.eof() );





    if (count >= 0){
        System.out.println("You encountered" + count "identical names.");
    else
        System.out.println("There was no name encountered more than once.");
    }

删除
if
语句末尾。
结束
if
语句

if (name1.equals(name2))
count++;
并分别为
if
else
添加大括号

if (count >= 0)
{
    System.out.println("You encountered" + count + "identical names.");
}
else
{
    System.out.println("There was no name encountered more than once.");
}   
应改为

if (count >= 0){
    System.out.println("You encountered" + count "identical names.");
} else {
    System.out.println("There was no name encountered more than once.");
}

您必须删除从if语句的末尾开始,就是这样。

很不清楚为什么您将代码的一部分标记为Javascript片段(它不是),然后在它后面得到其他代码。在
之前关闭
}
,在它之后打开一个新代码,即
}else{
+count“相同”
您在
计数后忘记了一个
+
这个问题是错误的,离题了,不应该回答:/您没有解释第一个错误:“)”expected for the“)”expected我在“count”之后缺少一个“+”就像这里有人建议的。对于第二个错误,括号不在正确的位置。两个错误都已更正。谢谢您的帮助!
if (count >= 0){
    System.out.println("You encountered" + count "identical names.");
} else {
    System.out.println("There was no name encountered more than once.");
}