1 Star 0 Fork 82

zscgrhg/Java

forked from 编程语言算法集/Java 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DecimalToOctal.java 624 Bytes
一键复制 编辑 原始数据 按行查看 历史
github-actions 提交于 2020-10-24 18:23 +08:00 . Formatted with Google Java Formatter
package Conversions;
import java.util.Scanner;
/** This class converts Decimal numbers to Octal Numbers */
public class DecimalToOctal {
/**
* Main Method
*
* @param args Command line Arguments
*/
// enter in a decimal value to get Octal output
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, k, d, s = 0, c = 0;
System.out.print("Decimal number: ");
n = sc.nextInt();
k = n;
while (k != 0) {
d = k % 8;
s += d * (int) Math.pow(10, c++);
k /= 8;
}
System.out.println("Octal equivalent:" + s);
sc.close();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/frostforest/Java.git
git@gitee.com:frostforest/Java.git
frostforest
Java
Java
master

搜索帮助