Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.NumberFormatException When I type "Exit"

user2363567Oct 12 2012 — edited Oct 12 2012
import java.util.Scanner;

public class ItemsQ2 {

public static void main(String[] args) {

String item = null;
int Iprice = 0;
int total_bill = 0;

do {

System.out.print("Enter Item: ");
Scanner Sitem = new Scanner(System.in);
item = Sitem.nextLine();

String test= item.replaceAll("\\D","");
Iprice = Integer.parseInt(test);

total_bill = Iprice + total_bill;
// System.out.print(test);
System.out.print("Your total bill is: " +total_bill);

} while (!item.equalsIgnoreCase("Exit"));
System.out.print("Your total bill is: " +total_bill);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 9 2012
Added on Oct 12 2012
2 comments
209 views