This is how you would do it:
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
int[] array = new int[input.length()];
for(int i = 0; i < input.length(); i++){
array[i] = Integer.parseInt(Character.toString(input.charAt(i)));
}
String.charAt(int position)
gets the Character located at a
certain position in the String.Character.toString(Characters ch)
converts a Character to a String.Integer.parseInt(String s)
converts a String to an Integer.
So, what the code does is it goes through each character in the string, converts that character to a String, and then uses the Integer.parseInt()
method in order to get that original character as a number.
array
is now an array of the digits of the number that the user inputted. This should answer your question.
3
solved How can user input a sequence of numbers into array// Java