java-十进制整数转换为十六进制整数

/**
 * 问题:十进制转换为十六进制
 * 
 * @author 三一
 *
 * @time 2018-7-18
 *
 */

import java.util.Scanner;

class Test {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入一个十进制的整数:");
		int mun = input.nextInt();

		String s = "";
		int shang = mun;
		int yu;
		while (shang != 0) {
			yu = shang % 16;
			shang = shang / 16;
			// *************
			char result;
			if (yu >= 9) {
				result = (char) ('A' + (yu - 10));
			} else {
				result = (char) ('0' + (yu - 0));
			}
			// *************
			s = result + s;
		}
		System.out.println(mun + "的十六进制是:" + s);
	}
}

 

你可能感兴趣的:(java)