java - Casting string into <Integer>ArrayList -


    scanner scan = new scanner(system.in);     system.out.println("enter sequence of numbers ending 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 cast string of numbers array. not adding correct vaule. keep getting 49 , 50. want store numbers user enters arraylist. can help?

 int y = num.charat(x); 

that give unicode codepoint character. 65 or 48 0.

you probablay want

 int y = integer.parseint(num.substring(x, x+1)); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -