user2879571
user2879571

Reputation: 1

jGRASP says my for loop is incorrect

here is my for loop... jGRASP says there is a problem beginning in the line with my for loop, I can't see the problem and would like some help to fix my code...

public class DirectoryLookup { public static void main(String[] args) throws IOException {

  if (args.length == 0) {
      System.out.println("Please supply data file");
      System.exit(0);
      }

  else {
      System.out.println("Database server is Ready for Number Lookups!");
      }

  File inputDataFile = new File(args[0]);
  Scanner inputFile = new Scanner(inputDataFile)
  Scanner input = new Scanner(input.in);

  int n = inputFile.nextInt();
  int list[] = new int[n];

  found = false;

  while (Scanner.hasNext()); {
     System.out.println("Enter number to check value");
     int x = input.nextInt();

     for (i = 0, i < n, i++); 
        if (x == list(i)); {
           found = true; break 
           System.out.println("x is in the list");

        else {
           System.out.println("x is not in the list");
           }
     }

Upvotes: 0

Views: 583

Answers (2)

Darth Sid
Darth Sid

Reputation: 69

The first problem that I see in your for loop is that you never declare i as an integer. You would have to say for(int i = 0... ).

The second problem that I see is that you are forgetting your brackets for the for loop. It is ending in a semi colon and not a bracket and closing bracket.

The third problem that I see is that you never close your if statement brackets. right now the else statement is in the if statement. which does not make any logical or syntactical sense.

Your while statement conditions are wrong also. Instead of scanner.blah you need to use the variable name used input or inputfile.

You never declared your boolean variable found.

Hope that helped,

Best regards

Upvotes: 0

rgettman
rgettman

Reputation: 178313

You have semicolons following your while condition, your for loop declaration, and your if condition. They need to be removed, otherwise Java will treat the semicolon itself as the body.

The semicolon is missing on your break statement, and the ending brace } is missing before your else.

Upvotes: 5

Related Questions