标签:can void 代码 算法 stack turn out 进制 imp
如题
import java.util.Scanner;
import java.util.Stack;
public class DecToOct {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int num = s.nextInt();
int octNum = decToOct(num);
System.out.print(octNum);
}
public static int decToOct(int num) {
int tempNum = num;
Stack<Integer> stack = new Stack<>();
while (tempNum != 0) {
int n = tempNum % 8;
stack.push(n);
tempNum /= 8;
}
int octNum = 0;
while (!stack.isEmpty()) {
int n = stack.pop();
octNum = octNum * 10 + n;
}
return octNum;
}
}
标签:can void 代码 算法 stack turn out 进制 imp
原文地址:https://www.cnblogs.com/coding-gaga/p/12984485.html