Advertisement
DulcetAirman

decimal integer to array

Dec 12th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1.  
  2.   public static void main(final String[] args) {
  3.     try (Scanner scan = new Scanner(System.in)) {
  4.       int n=scan.nextInt();
  5.       final int[] a = new int[(int) Math.floor(Math.log10(n) + 1)];
  6.       int rem;
  7.       int i=0;
  8.       while(n!=0)
  9.       {
  10.         rem=(n%10);
  11.         a[a.length - i - 1] = rem;
  12.         n = n/10;
  13.         i++;
  14.       }
  15.       System.out.println(Arrays.toString(a));
  16.     }
  17.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement