Scanner sc = new Scanner(System.in);
length = sc.nextLine();
length_to_play = Integer.parseInt(length);
I have tried using length.trim() and length.replaceAll() to discard the whitespaces, but didn't work. I'm having Exception in thread "main" java.lang.NumberFormatException.
Exception in thread "main" java.lang.NumberFormatException: For input string: "y"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at speedwords.first_activity(speedwords.java:27)
at speedwords.main(speedwords.java:338)