Created
May 16, 2018 02:59
-
-
Save thmain/0e52b8e4aca4248655e5079777b99ab3 to your computer and use it in GitHub Desktop.
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 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