Java 基本问题

1、Java 基本数据类型与引用数据类型
https://www.cnblogs.com/Latiny/p/8099581.html

案例:

class test {
    public static void main(String[] args){
        # 引用数据类型 = 基本数据结构 + 方法
        test t = new test();
        # 基本数据结构 
        char c1 = 'a';
        byte b1 = 2;
        short s1 = 13;
        int i1 = 12;
        long l1 = 123;
        double d1 = 1234;
        System.out.println(""+c1+i1);
        System.out.println(t.judgeType(c1));
    }

public String judgeType(Object temp) {
    if (temp instanceof Byte) {
        return "是Byte类型";
    } else if (temp instanceof Integer) {
        return "是Integer类型";
    } else if (temp instanceof Short) {
        return "是Short类型";
    } else if (temp instanceof String) {
        return "是String类型";
    } else if (temp instanceof Long) {
        return "是Long类型";
    } else if (temp instanceof Float) {
        return "是Float类型";
    } else if (temp instanceof Double) {
        return "是Double类型";
    } else if (temp instanceof Character) {
        return "是Character类型";
    } else {
        return "是引用数据类型";
    }
}
}

2、算术运算符

#错误: 不兼容的类型: 从double转换到int可能会有损失
int i1 = 0.1;

# 算数运算符中的强制转换
int i1 = (int)0.1;
int i1 *= 0.1;
# 结果为 0
System.out.println(i1);  

猜你喜欢

转载自blog.51cto.com/f1yinsky/2131315