Skip to content

Instantly share code, notes, and snippets.

@joohee
Created October 22, 2013 01:58
Show Gist options
  • Save joohee/7094066 to your computer and use it in GitHub Desktop.
Save joohee/7094066 to your computer and use it in GitHub Desktop.
cynap test java version
public class Cynap {
private static final int BASE = 26;
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("please insert value... ");
return;
}
System.out.println("input: " + args[0]);
int value = Integer.parseInt(args[0]);
int length = getAlphabetLength(value);
StringBuffer output = new StringBuffer();
for (int i = length; i > 1; i--) {
int divider = (int)Math.pow(BASE, i-1);
int quotient = value / divider;
if (quotient > BASE) {
quotient = BASE;
}
value -= divider * quotient;
output.append(itoalpha(quotient));
}
if (value > 0) {
output.append(itoalpha(value));
}
System.out.println("result: " + output.toString());
}
private static char itoalpha(int i) {
return (char)(i+64);
}
private static int getAlphabetLength(int value) {
boolean found = false;
int length = 1;
int baseOfLength = 0;
while (! found) {
baseOfLength += Math.pow(BASE, length);
if (baseOfLength >= value) {
found = true;
} else {
length++;
}
}
return length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment