Scanner scan = new Scanner(System.in);
System.out.println("Enter a sequence of numbers ending with 0.");
ArrayList<Integer> list = new ArrayList<Integer>();
String num = scan.nextLine();
for(int x=0; x < num.length(); x++){
System.out.println(num.charAt(x));
int y = num.charAt(x);
System.out.println(y);
list.add(y);
System.out.println(list);
}
Im trying to cast a string of numbers into a array. Its not adding the correct vaule. I keep getting 49 and 50. I want to store the numbers the user enters into the ArrayList. Can someone help?
int y = num.charAt(x)-48orCharacter.valueOf(num.charAt(x))since '0' is represented by 48, refer: asciitable.com