数据类型学习

JAVA

Write Once Run anywhere

JDK:java开发者工具

JRE:java 运行时环境

JVM:java虚拟机

image-20230314153055596

Hello world

public class HelloWorld {
    public static void main(String[] args) {

        System.out.println("hello,world!");
    }
}

public class Demo1 {
    public static void main(String[] args) {
        String a = "hello";
        int b = 10;
        System.out.println(a+b);

    }
}

基础数据类型

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

        int num1 = 10;
        byte num2 = 20;
        short num3  = 30;
        long num4 = 40;

        //小数:浮点数
        float num5 = 50.1F;
        double num6 = 3.14159265358979;

        //字符串
        char name = '牛';
        //string name1 = "赵云";

        //布尔值:是非
        boolean flag = true;
        boolean flag1 = false;
    }
}

数据类型扩展

public class Demo3 {
    public static void main(String[] args) {
        int i = 10;
        int i2 = 010; //八进制
        int i3 = 0x11; //十六进制0x


        System.out.println(i);
        System.out.println(i2);
        System.out.println(i3);
        System.out.println("==================================================================");
        //BigDecimal  数学工具类

         float f = 0.1f; //0.1
         double d = 1.0/10; //0.1
        System.out.println(f==d);
        System.out.println(f);
        System.out.println(d);

        float f1 = 1231654321321465431f;
        float d1 = f1 + 1;
        System.out.println(d1);
        System.out.println(d1==f1);

        System.out.println("==================================================================");

        char c1 = 'a';
        char c2 = '国';

        System.out.println(c1);
        System.out.println((int)c1); //强制转换

        System.out.println(c2);
        System.out.println((int)c2); //强制转换

        //所有的字符本质还是数字
        // 编码 Unicode

        System.out.println("hello\nworld");

        System.out.println("==================================================================");
        String ca = new String("hello world");
        String cb = new String("hello world");
        System.out.println(ca==cb);

        String cc = "helloworld";
        String cd = "helloworld";
        System.out.println(cc==cd);

        //布尔值扩展
        boolean flag = true;
        int a6 = 5;
        if (flag == true) {
            //if (flag)
            System.out.println("正确");
        }

    }
}

posted @   Myth426  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示