2 Replies Latest reply: Oct 12, 2012 7:36 AM by 939520 RSS

    java.lang.NumberFormatException When I type "Exit"

    user2363567
      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);
      }
      }