I am working on a dice game in a java program (jGRASP specifically) and it is kicking my can. I need to return a name and the number of dice per hand from the user input. Here is my (relevant) code so far:
import java.util.*;
public class DiceGame {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Welcom to the Lab 7 Dice Game.");
name();
dice();
}
public static String name(){
System.out.print("What is you name? ");
String name = input.next();
return name;
}
public static int dice(){
System.out.print("How many rolls per round? ");
int dice = input.nextInt();
return dice;
}
}
The method gives my entry line and asks the user for an String input as a name. That works just fine, it will print that out as intended. But when it moves on to calling the dice method, I get an "InputMismatchException" at "dice();" in main and at "int dice = input.nextInt();" in my dice method. Really, I am just looking for an explanation. I looked it up in the textbook I have, and looking it up elsewhere, but I cannot find an explanation.