2013-10-15 18 views
0

這裏是我的for循環... jGRASP說,有符合我的for循環中,我看不到問題的行開始一個問題,想一些幫助來解決我的代碼。 ..jGRASP說我的for循環是不正確

公共類DirectoryLookup { 公共靜態無效的主要(字串[] args)拋出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"); 
      } 
    } 

回答

5

你有以下的while條件,你for循環聲明,和你的if條件分號。他們需要被刪除,否則Java會將分號本身當作主體。

您的break聲明中缺少分號,結尾大括號}在您的else之前缺失。

0

,我在你看到for循環的第一個問題是,你永遠宣佈我作爲一個整數。你將不得不說for(int i = 0 ...)。

,我看到的第二個問題是,你忘了你的括號內爲for循環。它以分號結束,而不是括號和右括號。

,我看到的第三個問題是,你永遠閉上你的if語句括號。現在else語句在if語句中。這沒有任何邏輯或語法意義。

你的while語句條件也是錯誤的。您需要使用變量名稱input或inputfile來代替scanner.blah 。

你從未宣佈過你的布爾變量中。

希望,幫助,

最好的問候