Why my scanner still takes a space char

Viewed 127

Input : 1 2 3

Goal : Each of this number will be filled in a same array. Space will be excluded.

Scanner in = new Scanner(System.in);
String  n = in.nextLine();
System.out.println(n);

int[] nums = new int[n.length()];
for (int i = 0; i < n.length(); i++) {
     System.out.println(n.charAt(i));
     if (!String.valueOf(n.charAt(i)).equalsIgnoreCase(" ")) {
          nums[i] = Character.getNumericValue(n.charAt(i));
     }
}

I've no idea why still it includes space " ".

5 Answers
Related