-3

The error ')' expected is encountered on line 8; and the error 'else' without 'if' is found on line 9. This is only a part of the method. The beginning declares all needed variable (name1, name2, count), and states possible exceptions when reading the file. At this point, the program should already be reading the file in order to compare the names written in the file.

 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.");
    }
litelite
  • 2,857
  • 4
  • 23
  • 33
Carrie
  • 11
  • 1
  • 5

3 Answers3

1

Remove the ; at the end of the if statement. The ; ends the if statement.

if (name1.equals(name2))
count++;

And add braces for if and else separately.

if (count >= 0)
{
    System.out.println("You encountered" + count + "identical names.");
}
else
{
    System.out.println("There was no name encountered more than once.");
}   
Jerin Joseph
  • 1,087
  • 9
  • 17
  • You didn't explain the first error: **')' expected** – Andreas Aug 14 '17 at 18:55
  • For the **')' expected** I was missing a "+" after "count" like someone here suggested. And for the second error, the brackets were not at the right place. Both errors have been corrected. Thank you for your help! – Carrie Aug 14 '17 at 23:54
0
if (count >= 0){
    System.out.println("You encountered" + count "identical names.");
else
    System.out.println("There was no name encountered more than once.");
}

Should be changed to

if (count >= 0){
    System.out.println("You encountered" + count "identical names.");
} else {
    System.out.println("There was no name encountered more than once.");
}
Nicholas Hirras
  • 2,592
  • 2
  • 21
  • 28
-1

you must delete ; from end of if statement , that is it .