In my case, users can enter
f 0 ,f 1, f 2//1 digit p 0, p 1 ,p 2//1 digit j 0 1, j 0 2, j 1 0....(any combination of 0,1,2) //2 digits q ,Q //for quit
I use
str = scanner.nextLine();//get the whole line of input if(str.matches("[fpjq]\\s[012]"))......//check vaild input char1=str .charAt(0);//get the first letter
Then I want to get the next digit.
Any string method can extract the next digit from a string in Int format?
However, some errors still exist for my method. For example, he can exit the program for QQ or qq or q + any letters
Can best practices be provided?
Edit
e.g. p 0 1 char1 = str.charAt (0); // get p now i want to get 0 and 1 and save to int
source share