java定义变量的3个相关练习

package chapter1;

public class Practice3 {
    public static void main(String[] args) {
        //一开始没有乘客
        int count = 0;
        //第一站:上去一位乘客
        count = count + 1;
        //第二站:上去两位乘客,下去一位乘客
        count = count + 2 -1;
        //第三站:上去两位乘客,下去一位乘客
        count = count + 2 -1;
         //第四站:下去一位乘客,
        count = count - 1;
        //第五站:上去一位乘客
        count = count + 1;
        //请问:到终点站,车上一共几位乘客
        System .out .println(count) ;
    }
}

package chapter1;

public class Practice4 {
    public static void main(String[] args) {
        //byte
        byte b = 10 ;
        System .out .println(b) ;
        //short
        short s = 20;
        System .out .println(s) ;
        //int
        int i = 30;
        System .out .println(i) ;
        //long
        //如果要定义long 类型的变量
        //在数据值的后面需要加一个L作为后缀
        //L可以是大写的,也可以是小写的,但是一般是用大写
        long n = 999999999L;
        System .out .println(n) ;


        //float
        //注意点:定义float 类型变量的时候
        //数据值也需要加一个F作为后缀
        float f = 10.1F;
        System .out .println(f) ;
        //double
        double d = 20.2;
        System .out .println(d) ;

        //char
        char c = '中';
        System .out .println(c) ;

        //boolean
        //ture flase
        boolean o = true  ;
        System .out .println(o) ;
    }
}
package chapter1;

public class Practice5 {
    public static void main(String[] args) {
        //定义变量记录姓名
        String name = "黑马程序员" ;
        //定义变量记录年龄
        int age = 18 ;
        //定义变量记录性别
        char gender = '男';
        //定义变量记录身高
        double height = 180.1;
        //定义变量是否为单身
        //true 单身 false 不是单身
        boolean flag = true;
        System .out .println(name) ;
        System .out .println(age) ;
        System .out .println(gender) ;
        System .out .println(height) ;
        System .out .println(flag) ;

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

        //定义变量记录电影的名字
        String rename = "送初恋回家" ;
        //定义变量记录主演
        String toster = "刘鑫 张玉提 高元" ;
        //定义变量记录年份
        int year = 2020;
        //定义变量记录评分
        double grade = 9.0;
        //输出所有变量的值
        System .out .println(rename) ;
        System .out .println(toster) ;
        System .out .println(year) ;
        System .out .println(grade) ;

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


    }
}
  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值