Created
October 20, 2012 04:35
-
-
Save yao2030/3922026 to your computer and use it in GitHub Desktop.
conver a number to k-base
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Kary | |
{ | |
public static void main(String[] args) | |
{ | |
int i = Integer.parseInt(args[0]); | |
int k = Integer.parseInt(args[1]); | |
int v = 1; | |
while (v <= i/k) | |
v *= k; | |
int n = i; | |
while(v > 0) | |
{ | |
if (n < v) | |
{ | |
if ( n == 10) | |
System.out.print("A"); | |
else if ( n == 11) | |
System.out.print("B"); | |
else if ( n == 12) | |
System.out.print("C"); | |
else if ( n == 13) | |
System.out.print("D"); | |
else if ( n == 14) | |
System.out.print("E"); | |
else if ( n == 15) | |
System.out.print("F"); | |
else | |
System.out.print(n); | |
v /= k; | |
} | |
else { if ( n / v == 10) | |
System.out.print("A"); | |
else if ( n / v == 11) | |
System.out.print("B"); | |
else if ( n / v == 12) | |
System.out.print("C"); | |
else if ( n / v== 13) | |
System.out.print("D"); | |
else if ( n / v == 14) | |
System.out.print("E"); | |
else if ( n / v == 15) | |
System.out.print("F"); | |
else | |
System.out.print(n/v); | |
n -= (n/v) * k; | |
v /= k; | |
} | |
} | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment