法一:利用Integer.toString(n,进制)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(Integer.toString(n,6));
}
}
法二:计算
/*
120 / 6 20 余0
20 / 6 3 余2
3 / 6 0 余3
*/
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
StringBuilder stringBuilder = new StringBuilder();
while(n > 0) {
stringBuilder.append(n%6);
n /= 6;
}
System.out.println(stringBuilder.reverse());
}
}