Advertisement
Guest User

Why you do this to me java

a guest
Apr 6th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1.  static void cdTest(){
  2.        
  3.         int num = 523;
  4.         int d = 3;
  5.  
  6.         int[] cd=new int[d];
  7.         cd = cadaDigito(num, d);
  8.  
  9.         int i = d;
  10.         while(d-i!=d){
  11.             System.out.println(cd[d-i]);
  12.             i--;
  13.         }
  14.     }
  15.  
  16.  
  17.  
  18.     /**
  19.      * @param num cifra
  20.      * @param d   número de dígitos
  21.      * @return arreglo con cada dígito
  22.      */
  23.     static int[] cadaDigito(int num, int d) {
  24.         int cd[] = new int[d];
  25.         int c = num;
  26.         int i = 1;
  27.         double r = 0;
  28.         int a_Temp = 0;
  29.         double e = 0;
  30.         double m;
  31.  
  32.         do {
  33.             r = c / Math.pow(10, d - i);
  34.             a_Temp = (int) r;
  35.             cd[i - 1] = a_Temp;
  36.             e = r - a_Temp;
  37.             m = Math.pow(10, d - i);
  38.             c = (int)(e*m);
  39.             i++;
  40.         } while ((d - i) != -1);
  41.  
  42.         return cd;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement