JAVA学习第一天

HelloWord快捷键打印

public class helloword {
    //    PSVM即可输出
    public static void main(String[] arges) {
    //    sout即可输出
        System.out.print("hello word");
    }
}

JAVA的八大数据类型

public class hello {
    // psvm
    public static void main(String[] args) {
        // sout
        // 八大基本数据类型

        // 整数

        int num = 66;
        byte num1 = 127; //长度 -128~127
        short num3 = 30;
        long num4 = 30L; //long类型要在数字后面加L

        // 小数:浮点数

        float num5 = 1.123F; //float类型要在后面追加F
        double num6 = 3.1415926;

        // 字符
        char name = '肖';   //只能为一个中文

        //字符串
        String tearch = "xiao";

        //bool
        Boolean flag = true;
//        Boolean flag = false;

        System.out.println(tearch);
    }
}

// 快注释

强制转换

public class demo2 {
    public static void main(String[] args) {
        // 强制转换
        int i = 128;
        byte b = (byte) i;
        double c = i;
        System.out.println(b);
        System.out.println(c);
    }
}


/*
1.把高容量转换为低容量时,需要加强制转换
2.低容量到高容量时,直接转换
3.转换时可能存在内存溢出,或者精度问提
*/

举例

public class demo4 {
    public static void main(String[] args) {
        int mony = 1000000000;
        int year = 20;
        long total = mony * year; // 计算的结果 int已经超过最大长度,需要进行转换
        long total2 = mony * ((long) year);
        System.out.println(total);
        System.out.println(total2);
    }
}


--------------------------------------
-1474836480
20000000000

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值