I am getting this error when I run the following code and enter 5x5 for size. Not sure why?
When I enter 10x10 it seems to run ok but I'm not sure if the output is correct.
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)"
Here is my code
import java.util.Scanner;
public class CheckerBoard {
public static void main(String [] args){
Scanner userInput = new Scanner(System.in);
System.out.println("What two colors would you like your board to be?");
String colorOne = userInput.next();
String colorTwo = userInput.next();
do {
System.out.println("How big should the checker board be? (Square sizes only please)" + "\n"
+ "Please enter it like 4x4 with whatever numbers you choose.");
String boardSize = userInput.next();
int intOne = Integer.parseInt(boardSize.substring(0,boardSize.indexOf("x")));
System.out.println(boardSize.indexOf("x"));
int intTwo = Integer.parseInt(boardSize.substring(boardSize.indexOf("x")+1, boardSize.length()-1));
System.out.println(intOne);
} while(false);
}
}
//keep in mind that this program is not done yet, this is just a current issue I am having atm.