about summary refs log tree commit diff
path: root/usth/ICT2.2/labwork/1/Kary.java
blob: 51fd9af305752b7bb1000c7caa9925afb529cf53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Kary
{ 
  private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7',
                                        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

  public static void main(String... args)
  { 
    int n = Integer.parseInt(args[0]);
    List<Character> result = new ArrayList<Character>();
    for (int k = Integer.parseInt(args[1]); n > 0; n /= k)
      result.add(DIGITS[n % k]);

    Collections.reverse(result);
    for (char d : result)
      System.out.print(d);
    System.out.println();
  }
}