Casting string into ArrayList
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?
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.