...

View Full Version : Infinite while loop problem



riley.burris
12-06-2012, 06:25 AM
I've spent over 3 hours trying to figure out why this loop won't break. This loop reads in 3 values and stores them in an object. The entire program runs fine, its just that the loop won't' break. Assume that the method i call works fine. Also, SECSENT = EndSearchKeys. Also here's a sample input:
Lexus 2005 23678.0
Ford 2001 7595.0
Honda 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);
}

}

Philip M
12-06-2012, 08:12 AM
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.

BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum