Skip to content

Instantly share code, notes, and snippets.

@thmain
Created May 16, 2018 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/0e52b8e4aca4248655e5079777b99ab3 to your computer and use it in GitHub Desktop.
Save thmain/0e52b8e4aca4248655e5079777b99ab3 to your computer and use it in GitHub Desktop.
public class ConvertToBase3 {
public static String convertToBase3(int N){
String result = "";
while(N>0){
int rem = N%3;
N = N/3;
result = rem + result;
}
return result;
}
public static void main(String[] args) {
int N = 35;
System.out.println("Base 3 representation of " + N + ": " + convertToBase3(N));
N = 50;
System.out.println("Base 3 representation of " + N + ": " + convertToBase3(N));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment