import java.util.Scanner;
public class Decimail2HexConversion {
// 10进制转为16进制
public static String decimalToHex(int decimal){
String hex="";
while(decimal != 0){
int hexValue = decimal % 16;
hex=toHexChar(hexValue)+hex;
decimal=decimal / 16;
}
return hex;
}
// 16进制字符转换;
public static char toHexChar(int hexValue){
if(hexValue <=9 && hexValue >=0){
return (char)(hexValue+ '0');
}
else
return (char)(hexValue-10+ 'A');
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("Enter a decimal number:");
int decimal = in.nextInt();
System.out.println("转化为16进制为:"+decimalToHex(decimal));
}
}
单引号引的数据 是char类型的 双引号引的数据 是String类型的
单引号只能引一个字符
而双引号可以引0个及其以上
基本类型变量在内存中存储的是一个基本类型值,而引用类型变量存储的是一个引用,它指向对象在内存中的位置;
349

被折叠的 条评论
为什么被折叠?



