Java new array value per number -
i'm writing program (code shown below) user can input string numbers. these converted string integer. want new array, each individual number value. if user writes "15623" want array {1, 5, 6, 2, 3} know how it?
string getnumbers = textfield.gettext(); string[] ary = getnumbers.split(" "); int intnumbers = integer.parseint(getnumbers); int iarr[] = {intnumbers}; arrays.sort(iarr); (int number : iarr) { textfield.settext("" + number); }
use charat
specific characters , getnumericvalue
convert character digit :
string nums="1235325"; int[] iarr = new int[nums.length ()]; (int = 0; < nums.length (); i++) { iarr[i]=character.getnumericvalue (nums.charat (i)); } arrays.sort (iarr); system.out.println (arrays.tostring (iarr));
output :
[1, 2, 2, 3, 3, 5, 5]
Comments
Post a Comment