プログラムに、センチネル値に到達しない while ループがあります。プログラムは基本的に、string、int、および double を含むデータベースを読み取り、ループバックします。私の問題は、センチネルを読み取っていないようで、無限ループが発生することです。私はこれを何時間も修正しようとしたので、どんな支援も非常に役に立ちます. サンプル入力は、EndSearchKeys が SECSENT に等しい場合、次のようになります。
また、呼び出されたメソッドは問題ではないと仮定します。これは、既に削除して再度テストしたためです。
レクサス 2005 23678.0
フォード 2001 7595.0
ホンダ 2004 15500.0
EndSearchKeys
while(scan.hasNext())
{
if(carMake.equals(SECSENT))
{
break;
}
if(scan.hasNextInt())
{
carYear = scan.nextInt();
}
else
{
System.out.println("ERROR - not an int");
System.exit(0);
}
if(scan.hasNextDouble())
{
carPrice = scan.nextDouble();
}
else
{
System.out.println("ERROR - not a double");
System.exit(0);
}
Car key = new Car(carMake, carYear, carPrice);
// Stores the output of seqSearch in pos.
// If the debug switch is on, then it prints these statements.
if(DEBUG_SW == true)
{
System.out.println("Search, make = " + key.getMake());
System.out.println("Search, year = " + key.getYear());
System.out.println("Search, price = " + key.getPrice());
}
System.out.println("key =");
System.out.println(key);
pos = seqSearch(carArr, count, key);
if(pos != -1)
{
System.out.println("This vehicle was found at index = " + pos);
}
else
{
System.out.println("This vehicle was not found in the database.");
}
if(scan.hasNext())
{
carMake = scan.next();
}
else
{
System.out.println("ERROR - not a String");
System.exit(0);
}
}