标题: 为什么强转不了呢? [打印本页] 作者: 张小贝 时间: 2014-1-6 11:38 标题: 为什么强转不了呢? public class OperateDemo {
public static void main(String[] args){
int num = 60;
int n1 = num&15;
System.out.println(n1>9?((char)(n1-10+'A')):n1);
num = num >> 4;
int n2 = num &15;
System.out.println(n1>9?((char)(n2-10+'A')):n2);
}
} 作者: forDream 时间: 2014-1-6 12:49
public class OperateDemo {
public static void main(String[] args) {
int num = 60;
int n1 = num & 15;
if (n1 > 9) {
char c = (char) (n1 - 10 + 'A');
System.out.println(c);
} else
System.out.println(n1);
num = num >> 4;
int n2 = num & 15;
if (n1 > 9) {
char c = (char) (n2 - 10 + 'A');
System.out.println(c);
} else
System.out.println(n2);