基本数据类型、数据类型转化、运算符

一、基础语言:

1 基本数据类型:(一字节等于八位)
1.1 整数型:byte、short、int、long
1.2 浮点型:float、double
1.3 字符型:char
1.4 布尔型:boolean(一个字节、一位)

package cz.oneday.csdn;

public class number {
    public static void main(String[] args) {
    //整型
        byte b=19-5;
        short s=200/10;
        int i=10;
        long l=11111111L*11111111111111111l;
        System.out.println(b);
        System.out.println(s);
        System.out.println(i);
        System.out.println(l);
//浮点型
        float f=33.33f;
        double d=123456.1234;
        System.out.println(f);
        System.out.println(d);
//字符型
        char ch='a';
        char ch1=97;
        System.out.println(ch);
        System.out.println(ch1);
//布尔值
        boolean b1=true;
        boolean b2=false;
        System.out.println(b1);
        System.out.println(b2);




    }

}

在这里插入图片描述

2 数据类型转化:
2.1 隐式转化:byte->short->int->long->float->double
2.2 显示转化:double->int、float->long、double->char

package cz.oneday.csdn;

public class Change {
    public static void main(String[] args) {
        //隐式转换
         byte b=127;
         int i=360;
         float f=360.36f;
         char c='a';
         double d=45.1234;
        System.out.println("byte+float="+(b+f));
        System.out.println("byte+int="+(b+i));
        System.out.println("byte+char="+(b+c));
        System.out.println("double+char="+(d+c));
        //显示转化
        int a=(int)45.23;
        long b1=(long)123.2f;
        char c1=(char)97.12;
        System.out.println("double->int\t"+a);
        System.out.println("float->long \t"+b1);
        System.out.println("double->char\t"+c1);


    }
}

在这里插入图片描述

3.运算符:(&&||)
3.1 a++,++b
3.2 a1–,–b1
3.3 &&与||

package cz.oneday.csdn;

public class chaaar {
    public static void main(String[] args) {
        int s,s1,s2,s3;
        int a=1,a1=1,b=1,b1=1;
//a++
        System.out.println(".................a++.....................");
        a++;
        System.out.println("a="+a);
        s=a++;
        System.out.println("a="+a+"\ts="+s);
//++b
        System.out.println(".................++b.....................");
        ++b;
        System.out.println("b="+b);
        s1=++b;
        System.out.println("b="+b+"\ts1="+s1);
//a1--
        System.out.println(".................a1--.....................");
        a1++;
        System.out.println("a1="+a1);
        s2=a++;
        System.out.println("a1="+a1+"\ts2="+s2);
//--b1
        System.out.println("................--b1......................");
        ++b1;
        System.out.println("b1="+b1);
        s3=++b1;
        System.out.println("b1="+b1+"\ts3="+s3);
        System.out.println("...................&&和||..................");
        int x=3,y=6;
        boolean re=((x>y)&&(x!=y));
        boolean re1=((x>y)||(x!=y));
        System.out.println("....&&"+re);
        System.out.println("。。。||"+re1);

    }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值