Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void cdTest(){
- int num = 523;
- int d = 3;
- int[] cd=new int[d];
- cd = cadaDigito(num, d);
- int i = d;
- while(d-i!=d){
- System.out.println(cd[d-i]);
- i--;
- }
- }
- /**
- * @param num cifra
- * @param d número de dígitos
- * @return arreglo con cada dígito
- */
- static int[] cadaDigito(int num, int d) {
- int cd[] = new int[d];
- int c = num;
- int i = 1;
- double r = 0;
- int a_Temp = 0;
- double e = 0;
- double m;
- do {
- r = c / Math.pow(10, d - i);
- a_Temp = (int) r;
- cd[i - 1] = a_Temp;
- e = r - a_Temp;
- m = Math.pow(10, d - i);
- c = (int)(e*m);
- i++;
- } while ((d - i) != -1);
- return cd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement