Created
January 22, 2014 09:22
-
-
Save blazindragon/8555830 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import java.util.ArrayList; | |
| public class BaseConversion { | |
| public static void main(String...z) { | |
| if (z.length !=2) { | |
| System.out.printf("Usage: java BaseConversion <integer> <base>\n"); | |
| System.exit(1); | |
| } | |
| ArrayList<Integer> result = new ArrayList<Integer>(); | |
| int num = Integer.parseInt(z[0]); | |
| int base = Integer.parseInt(z[1]); | |
| int remainder = 0; | |
| while (num !=0) { | |
| remainder = num % base; | |
| num = num / base; | |
| result.add(remainder); | |
| } | |
| String res = ""; | |
| for (int i = result.size() - 1; i >= 0; --i) { | |
| res += result.get(i); | |
| } | |
| System.out.printf("%s to %s = %s\n", z[0], z[1], res); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yo, do you have skype? how can i contact you?