进制转换

进制转换

在这里插入图片描述

import java.util.Scanner;

public class Oj {

	public static int toDec(int num) {// 十进制四位数字之和
		int a = num / 1000;
		int b = num / 100 % 10;
		int c = num / 10 % 10;
		int d = num % 10;
		int result = a + b + c + d;
		return result;
	}

	public static int toHex(int num) {// 十六进制四位数字之和
		int result = 0;
		while (num != 0) {
			int x = num & 0xF;
			result += x;
			num = (num >>> 4);
		}
		return result;
	}

	public static int toDuo(int num) {// 十二进制四位数字之和
		int result = 0;
		int x = 0;// 定义一个int变量接受
		while (num != 0) {// 除十二取余法
			x = num % 12;
			num = num / 12;
			result += x;
		}
		return result;
	}

	public static void main(String[] args) {
		int n = 0;
		Scanner scan = new Scanner(System.in);
		if (scan.hasNextInt()) {
			n = scan.nextInt();
		}
		scan.close();
		if (toHex(n) == toDec(n) && toDec(n) == toDuo(n)) {
			System.out.println(n + " is a Sky Number.");
		} else
			System.out.println(n + " is not a Sky Number.");

	}

}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值