Hi,
I searching for a way to split up the individual numbers of a variable(type=long) to several integers in an Array, so if i have the long x=54321, i later have an array a with the value a=5, a=4, and so on.
public static ArrayList<Integer> test(int x) { ArrayList<Integer> intList = new ArrayList<Integer>(); int i =1; while (x!=0) { int array = x%(int) (Math.pow(10,i)); x=x-array; if(i>1) { intList.add(array/(int) (Math.pow(10,i-1))); } else { intList.add(array); } i++; } return intList; }
public static ArrayList<Long> test(long x) { ArrayList<Long> longList = new ArrayList<Long>(); int i =1; while (x!=0) { long array = x%(long) (Math.pow(10,i)); x=x-array; if(i>1) { longList.add(array/(long) (Math.pow(10,i-1))); } else { longList.add(array); } i++; } return longList; }
runTime=makeRTime(rTime); int Lenght=getLenght(rTime); while(Lenght!=0){ Number n=new Number(runTime[Lenght]); }
// with long x = 54321; // use String xStr = "" + x; int[] a = new int[xStr.length()]; for (int i=0; i<a.length; i++) a[i] = Integer.valueOf(xStr.substring(i, i+1));