The only data type I'm using is int - so I don't see where this error is coming from. I use the same format in a previous section and I get no errors.
package graduationplanner; import java.util.Scanner; import java.util.ArrayList; public class GraduationPlanner { public static void main(String[] args) { Scanner in = new Scanner(System.in); final int MINCU = 12; final int TUITIONCOST = 2890; //stores value for tuition cost per term final int TERMMONTHS = 6; //stores value for number of months in a term int sum = 0; System.out.println("Welcome to the Western Governor's University Graduation Planner! \nWe will calculate the number of terms you have left until graduation, \nalong with the amount of tuition you have left to pay. \nWe will also provide the number of months until graduation! \nLet's get started by asking a few questions."); System.out.println("How many CU's are required for your degree?"); //Prompts user for the total number of CU's for degree and stores in variable int totalCU = in.nextInt(); //storing user input if (totalCU <= 0){ //verification on positive input by user System.out.println("That's not right! Enter a number higher than zero!"); System.out.println("How many CU's are required for your degree?"); totalCU = in.nextInt(); //stores corrected number } //System.out.println(totalCU); //Outputting number entered for check ArrayList<Integer> leftCU = new ArrayList<>(); { System.out.println("Please enter one at a time the number of CU's for each class that is left to complete. Enter Q when done."); leftCU.add(in.nextInt()); while (in.hasNextInt()){ leftCU.add(in.nextInt());} for(int i=0; i < leftCU.size(); i++){ sum = sum + leftCU.get(i);} } //System.out.println(leftCU); System.out.println(sum); System.out.println("How many CU's are you planning on taking per term?"); //Prompts user for the number of CU's per term int perTerm = in.nextInt(); //storing user input if (perTerm < MINCU){ //verification on positive input by user System.out.println("12 CU's are required per term. Try a higher number!"); System.out.println("How many CU's are required for your degree?"); perTerm = in.nextInt();} //stores corrected number System.out.println(perTerm); int termLeft = sum/perTerm; //Calculates number of terms left int totalTuition = termLeft * TUITIONCOST; //Calculates the amount of tuition left to pay int monthsLeft = termLeft * TERMMONTHS; //Calculates the number of months left System.out.println("+----------------------------------------+"); System.out.println("|Number of Terms left is: " + termLeft + "|"); System.out.println("|Total amount of Tuition left is: " + totalTuition + "|"); System.out.println("|Number of Months left is: " + monthsLeft + "|"); System.out.println("+----------------------------------------+"); System.out.println("Thank you for using the WGU Graduation Planner"); } }
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at graduationplanner.GraduationPlanner.main(Graduatio nPlanner.java:37)