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("------------------------------") ; } }