java - String to Array Int -
write function takes number represented string argument, example "12345"
or "4321432143214321"
, returns digits of number in array.
your function should create int[] array 1 digit of number per element.
can please hint how can approach problem?
public int[] converttoarray(string str){ int array[] = new int[str.length()]; for(int = 0; < array.length; i++){ try{ array[i] = integer.parseint(str.substring(i,i+1)); }catch(numberformatexception e){ e.printstacktrace(); array[i] = 0; } } return array; }
Comments
Post a Comment