2013-07-19 24 views
0
void searchForPopulationChange() 
    { 
    String goAgain; 
    String response; 
    int input; 
    int searchCount = 0; 
    boolean found = false; 
    boolean search = false; 


    while(search == false) 
    { 

     System.out.println ("Enter the Number for Population Change to be found: "); 
     input = scan.nextInt(); 


     for (searchCount = 0; searchCount < populationChange.length; searchCount++) 
     { 
      if (populationChange[searchCount] == input) 
      { 
       System.out.print(""+countyNames[searchCount]+" County/City with a population of "+populationChange[searchCount]+" individuals\n"); 
       found = true; 
      } 

     } 

     if (found == false) { 
      System.out.println("No records found!"); 
     } 


     System.out.println("\n\n-------------------------------------------------------------------------"); 
     System.out.println("\n\tDo you want to enter data for another Course? Type Yes or No: "); 
     response = scan.nextLine(); //the response is already recognized - thus ends or restarts the program  

     if (response.equalsIgnoreCase("yes")); 
     { 
      search = false; 
     } 

     if (response.equalsIgnoreCase("no")); 
     { 
      search = true; 
     }  



    } 


    } 

} 你好! 这是我的程序到目前为止, 基本上, 当while循环结束, 我需要它来提示用户,如果他希望再次执行该程序。 是或否? 我得到提示打印 但是,扫描功能不起作用。 有什么建议吗?试图获得Yes // No提示符。不会接受回复

+0

我建议你删除所有你的代码中克鲁夫特这是无关的问题。 – bdares

+0

这个问题似乎是题外话题,因为它是关于TYPO – nachokk

+0

它可能有助于链接到pastebin中的所有代码。但看起来像马克已经回答,低于 – Coffee

回答

7

if (response.equalsIgnoreCase("yes")); 

if (response.equalsIgnoreCase("no")); 
+0

好抓,微妙;-) – Coffee

+0

大声笑,这是一个优势,把左括号旁边的右括号:-) –

+0

@MarkM你是惊人的 – user2517185

1

您另外一个问题,删除分号(旁边后分号if S)将成为事实,你正在使用nextLinenextInt它不会消耗新线标记,所以首先nextLine将返回空字符串。要摆脱它尝试

input = scan.nextInt(); 
scan.nextLine();//to consume new line mark 

input = Integer.parseInt(scan.nextLine());