小乐乐在课上学习了二进制八进制与十六进制后,对进制转换产生了浓厚的兴趣。因为他的幸运数字是6,所以他想知道一个数表示为六进制后的结果。请你帮助他解决这个问题。
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.close(); base6(n); } public static void base6(int n) { int[] base_6 = new int[100]; int i = 0; while (n > 0) { base_6[i] = n % 6; //十进制转其他进制:先余上目标进制数,再除目标进制数,循环往复。 n /= 6; i++; } //反向输出,因为上面最后多加了个1,所以先减减。 for (i--; i >= 0; i--) { System.out.print(base_6[i]); } } }
import java.util.Scanner; import java.math.BigInteger; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case String num = in.next(); BigInteger b = new BigInteger(num); System.out.println(b.toString(6)); } } }
import java.util.Scanner; import java.util.ArrayList; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = in.nextInt(); ArrayList<Integer> array = new ArrayList<Integer>(); while(a!=0){ array.add(a%6); a=a/6; } for(int i=array.size()-1;i>=0;i--){ System.out.print(array.get(i)); } } }
import java.util.*; public class Main{ public static String tosix(int n) { if (n == 0) return "0"; String six = ""; while (n != 0) { six=n%6+six; n/=6; } return six; } public static void main(String love[]){ Scanner input=new Scanner(System.in); int n=input.nextInt(); System.out.print(tosix(n)); } }
import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); List<Integer> list = new LinkedList<>(); int k = n; int h = n; while (h >= 6) { k = h % 6; list.add(0, k); h = h / 6; } list.add(0, h); for (Integer m : list) { System.out.print(m); } } }
import java.util.Scanner ; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); StringBuilder r = new StringBuilder(); while(n>0){ r.append( n%6 ); n /= 6 ; } System.out.println( r.reverse()); } }