diff --git "a/51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/.gitignore" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/.gitignore" similarity index 100% rename from "51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/.gitignore" rename to "51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/.gitignore" diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/.name" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/.name" new file mode 100644 index 0000000000000000000000000000000000000000..fcc71c0946c40b506e398958937252e125380e9d --- /dev/null +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/.name" @@ -0,0 +1 @@ +bifen.java \ No newline at end of file diff --git "a/51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/\347\273\203\344\271\240.iml" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267.iml" similarity index 100% rename from "51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/\347\273\203\344\271\240.iml" rename to "51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267.iml" diff --git "a/51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/misc.xml" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/misc.xml" similarity index 100% rename from "51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/misc.xml" rename to "51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/misc.xml" diff --git "a/51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/modules.xml" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/modules.xml" similarity index 50% rename from "51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/modules.xml" rename to "51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/modules.xml" index 48ea5861da21af37059843eb67611f13dc4af2d3..afc68bdc2026b46c7115b2c864ab98a5e21e9176 100644 --- "a/51\345\217\267 \347\250\213\350\210\234/\347\273\203\344\271\240/.idea/modules.xml" +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/modules.xml" @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/vcs.xml" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/vcs.xml" new file mode 100644 index 0000000000000000000000000000000000000000..b2bdec2d71b6a5ce4ae49efc37516809c50e4d5e --- /dev/null +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/.idea/vcs.xml" @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/bifen.java" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/bifen.java" new file mode 100644 index 0000000000000000000000000000000000000000..1ed48463ad9b4db9aa2bb50745745b9e0689c01f --- /dev/null +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/bifen.java" @@ -0,0 +1,22 @@ +import java.util.Scanner; +//if语句格式 +//中国足球队吊打日本鬼子队足球队的比分 +public class bifen { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入中国队的分数"); + int China = sc.nextInt(); + System.out.println("请输入日本队的分数"); + int japan = sc.nextInt(); + + if(China<=japan){ + System.out.println("还需努力。"); + } else if(China-japan>20){ + System.out.println("国家奖励运动员全球游"); + } else if(China-japan>=10){ + System.out.println("国家奖励运动员全国游。"); + } else if(China-japan>0){ + System.out.println("国家奖励运动员一顿大餐。"); + } + } +} diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/duanluhuo.java" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/duanluhuo.java" new file mode 100644 index 0000000000000000000000000000000000000000..e888cfc340873c92ba29b7712132e86d0113bebb --- /dev/null +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/duanluhuo.java" @@ -0,0 +1,26 @@ +import java.util.Scanner; +//短路逻辑运算符格式 +public class duanluhuo { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入两位整数A"); + int a = sc.nextInt(); + System.out.println("请输入两位整数B"); + int b = sc.nextInt(); + double c = a+b; + int as = a/10%10; + int ag = a%10; + int bs = b/10%10; + int bg = b%10; + System.out.println("------------------"); + if (as%3==0 || ag%3==0){ + System.out.println("true"); + }else if (bs%3==0 || bg%3==0){ + System.out.println("false"); + }else if (c%3==0){ + System.out.println("true"); + }else{ + System.out.println("false"); + } + } +} diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/height.java" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/height.java" new file mode 100644 index 0000000000000000000000000000000000000000..1b3b4b28fd9a3f9198d692e4ad254f34415a8e9a --- /dev/null +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/height.java" @@ -0,0 +1,20 @@ +import java.util.Scanner; +//5.身高是具有遗传性的,子女的身高和父母的身高有一定的关系。假定,父母和子女的身高遗传关系如下: +// +//> 儿子身高(厘米)=(父亲身高+母亲身高) ×1.08÷2 +//> +//> 女儿身高(厘米)=(父亲身高×0.923+母亲身高) ÷2 +//> +//> 现有父亲身高177CM,母亲身高165CM。求子女身高分别预计为多少?【使用变量的定义和算术运算符完成本题】 +public class height { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入父亲身高"); + float F = sc.nextFloat(); + System.out.println("请输入母亲身高"); + float M = sc.nextFloat(); + + System.out.println("儿子身高:"+(F+M)*1.08/2); + System.out.println("女儿身高:"+(F*0.923+M)/2); + } +} diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/bifen.class" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/bifen.class" new file mode 100644 index 0000000000000000000000000000000000000000..5d9fbbb934e624bfd148ed71da0318e45e8c2936 Binary files /dev/null and "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/bifen.class" differ diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/duanluhuo.class" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/duanluhuo.class" new file mode 100644 index 0000000000000000000000000000000000000000..11919397fd7cdc425b4daa1ee041cadc465633ec Binary files /dev/null and "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/duanluhuo.class" differ diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/height.class" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/height.class" new file mode 100644 index 0000000000000000000000000000000000000000..c1fc29bd46384a6392d5a14f24e00ce04ca42e10 Binary files /dev/null and "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/height.class" differ diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/sanyuanyunsuanfu.class" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/sanyuanyunsuanfu.class" new file mode 100644 index 0000000000000000000000000000000000000000..411d1ed5fb60c741496894ceb3ccf2355e4e3490 Binary files /dev/null and "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/sanyuanyunsuanfu.class" differ diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/youhui.class" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/youhui.class" new file mode 100644 index 0000000000000000000000000000000000000000..768820c92e2bf793539f0685137543d3dceb0f87 Binary files /dev/null and "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/youhui.class" differ diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/yunsuanfu.class" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/yunsuanfu.class" new file mode 100644 index 0000000000000000000000000000000000000000..ce62bc1c6583707402fbdb0e7b7370b026d64d3d Binary files /dev/null and "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/out/production/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/yunsuanfu.class" differ diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/sanyuanyunsuanfu.java" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/sanyuanyunsuanfu.java" new file mode 100644 index 0000000000000000000000000000000000000000..08f1bcd3a662e9ecbd97751a539f5f856228d796 --- /dev/null +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/sanyuanyunsuanfu.java" @@ -0,0 +1,18 @@ +import java.util.Scanner; +//三元运算符格式 +//3.利用三元运算符求任意三个数中最大者 【三元】 +public class sanyuanyunsuanfu { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入数据A"); + int a = sc.nextInt(); + System.out.println("请输入数据B"); + int b = sc.nextInt(); + System.out.println("请输入数据C"); + int c = sc.nextInt(); + + int E = a>b?a:b; + int F = E>c?E:c; + System.out.println("最大值为:"+F); + } +} diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/youhui.java" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/youhui.java" new file mode 100644 index 0000000000000000000000000000000000000000..1acfdae5da53b33866dab0f8a22b076124e78ee8 --- /dev/null +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/youhui.java" @@ -0,0 +1,25 @@ +import java.util.Scanner; + +public class youhui { + //小明想在食堂打包一份午饭,商家的优惠方式如下:鱼香肉丝单点24元,油炸花生米单点8元, + // 米饭单点3元。订单满30元8折优惠。鱼香肉丝优惠价16元,但是优惠价和折扣不能同时使用。 + // 那么这个小伙要点这三样东西,最少要花多少钱? + // 【使用算术运算符、赋值运算符和三元运算符联合完成本题】 + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("米饭单点金额"); + int a = sc.nextInt(); + System.out.println("鱼香肉丝单点金额"); + int b = sc.nextInt(); + System.out.println("油炸花生米单点金额"); + int c = sc.nextInt(); + System.out.println("鱼香肉丝优惠金额"); + int e = sc.nextInt(); + double f=e+b+c;//27 + double g=(a+b)*0.8+c;//28.6 + double h=(a+b+c)*0.8;//28 + double ss=f>g?g:f; + double dd=ss>h?h:ss; + System.out.println("要点这3个东西,最少要花"+dd+"块。"); + } +} diff --git "a/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/yunsuanfu.java" "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/yunsuanfu.java" new file mode 100644 index 0000000000000000000000000000000000000000..33256fd39a3d5af7722fb511f035812ce21672a0 --- /dev/null +++ "b/51\345\217\267 \347\250\213\350\210\234/2022\345\271\26422\346\234\21030\346\227\245\344\275\234\344\270\232 51\345\217\267/yunsuanfu.java" @@ -0,0 +1,26 @@ +import java.util.Scanner; +//红茶妹妹有21元钱,她攒了几天钱之后自己的钱比原来的两倍还多三块。绿茶妹妹有24元钱,她攒了几天钱之后自己的钱正好是原来的两倍。 +// +//- 那么红茶和绿茶现在的钱一样多,请问对么?【使用赋值运算符和算术运算符计算各自的钱,使用比较运算符对比大小】 +public class yunsuanfu { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入红茶妹妹的金额"); + int hc = sc.nextInt(); + System.out.println("请输入绿茶妹妹的金额"); + int lc = sc.nextInt(); + double A =(hc*2+3); + double B =(lc*2); + + System.out.println(hc==lc); + if (A==B){ + System.out.println("对的"); + } + else if (A>B){ + System.out.println("绿茶多"); + } + else if (A | a>b,判断a是否大于b,成立为true,不成立为false | +| >= | a>=b,判断a是否大于等于b,成立为true,不成立为false | +| < | a b); // false +System.out.println(a >= b); // false +System.out.println(a < b); // true +System.out.println(a <= b); // true + +// 关系运算的结果肯定是boolean类型,所以也可以将运算结果赋值给boolean类型的变量 +boolean flag = a > b; +System.out.println(flag); // 输出false +~~~ + +### 逻辑运算符(应用) + +逻辑运算符把各个运算的关系表达式连接起来组成一个复杂的逻辑表达式,以判断程序中的表达式是否成立,判断的结果是 true 或 false。 + +| 符号 | 作用 | 说明 | +| ---- | -------- | -------------------------------------------- | +| & | 逻辑与 | a&b,a和b都是true,结果为true,否则为false | +| \| | 逻辑或 | a\|b,a和b都是false,结果为false,否则为true | +| ^ | 逻辑异或 | a^b,a和b结果不同为true,相同为false | +| ! | 逻辑非 | !a,结果和a的结果正好相反 | + +```java +//定义变量 +int i = 10; +int j = 20; +int k = 30; + +//& “与”,并且的关系,只要表达式中有一个值为false,结果即为false +System.out.println((i > j) & (i > k)); //false & false,输出false +System.out.println((i < j) & (i > k)); //true & false,输出false +System.out.println((i > j) & (i < k)); //false & true,输出false +System.out.println((i < j) & (i < k)); //true & true,输出true +System.out.println("--------"); + +//| “或”,或者的关系,只要表达式中有一个值为true,结果即为true +System.out.println((i > j) | (i > k)); //false | false,输出false +System.out.println((i < j) | (i > k)); //true | false,输出true +System.out.println((i > j) | (i < k)); //false | true,输出true +System.out.println((i < j) | (i < k)); //true | true,输出true +System.out.println("--------"); + +//^ “异或”,相同为false,不同为true +System.out.println((i > j) ^ (i > k)); //false ^ false,输出false +System.out.println((i < j) ^ (i > k)); //true ^ false,输出true +System.out.println((i > j) ^ (i < k)); //false ^ true,输出true +System.out.println((i < j) ^ (i < k)); //true ^ true,输出false +System.out.println("--------"); + +//! “非”,取反 +System.out.println((i > j)); //false +System.out.println(!(i > j)); //!false,,输出true +``` + +### 短路逻辑运算符(理解) + +| 符号 | 作用 | 说明 | +| ---- | ------ | ---------------------------- | +| && | 短路与 | 作用和&相同,但是有短路效果 | +| \|\| | 短路或 | 作用和\|相同,但是有短路效果 | + +在逻辑与运算中,只要有一个表达式的值为false,那么结果就可以判定为false了,没有必要将所有表达式的值都计算出来,短路与操作就有这样的效果,可以提高效率。同理在逻辑或运算中,一旦发现值为true,右边的表达式将不再参与运算。 + +- 逻辑与&,无论左边真假,右边都要执行。 + +- 短路与&&,如果左边为真,右边执行;如果左边为假,右边不执行。 + +- 逻辑或|,无论左边真假,右边都要执行。 + +- 短路或||,如果左边为假,右边执行;如果左边为真,右边不执行。 + +~~~java +int x = 3; +int y = 4; +System.out.println((x++ > 4) & (y++ > 5)); // 两个表达都会运算 +System.out.println(x); // 4 +System.out.println(y); // 5 + +System.out.println((x++ > 4) && (y++ > 5)); // 左边已经可以确定结果为false,右边不参与运算 +System.out.println(x); // 4 +System.out.println(y); // 4 +~~~ + +### 三元运算符(理解) + +三元运算符语法格式: + +~~~java +关系表达式 ? 表达式1 : 表达式2; +~~~ + +解释:问号前面的位置是判断的条件,判断结果为boolean型,为true时调用表达式1,为false时调用表达式2。其逻辑为:如果条件表达式成立或者满足则执行表达式1,否则执行第二个。 + +举例: + +~~~java +int a = 10; +int b = 20; +int c = a > b ? a : b; // 判断 a>b 是否为真,如果为真取a的值,如果为假,取b的值 +~~~ + +### 分支结构之if语句 + +#### if语句格式1(理解) + +~~~java +格式: +if (关系表达式) { + 语句体; +} +~~~ + +执行流程: + +①首先计算关系表达式的值 + +②如果关系表达式的值为true就执行语句体 + +③如果关系表达式的值为false就不执行语句体 + +④继续执行后面的语句内容 + +```java +public class IfDemo { + public static void main(String[] args) { + System.out.println("开始"); + + // 如果年龄大于18岁, 就可以上网吧 + int age = 17; + + if(age >= 18){ + // int a = 10; + System.out.println("可以上网吧"); + } + + System.out.println("结束"); + } +} +``` + +#### if语句格式2(理解) + +~~~java +格式: +if (关系表达式) { + 语句体1; +} else { + 语句体2; +} +~~~ + +执行流程: + +①首先计算关系表达式的值 + +②如果关系表达式的值为true就执行语句体1 + +③如果关系表达式的值为false就执行语句体2 + +④继续执行后面的语句内容 + +```java +// 任意给出一个整数,请用程序实现判断该整数是奇数还是偶数,并在控制台输出该整数是奇数还是偶数。 +public class Demo2If { + public static void main(String[] args) { + // 程序判断一个数, 是奇数还是偶数 + int num = 9; + + if(num % 2 == 0){ + System.out.println("偶数"); + }else{ + System.out.println("奇数"); + } + } +} +``` + +#### if语句格式3(理解) + +~~~java +格式: +if (关系表达式1) { + 语句体1; +} else if (关系表达式2) { + 语句体2; +} +… +else { + 语句体n+1; +} +~~~ + +执行流程: + +①首先计算关系表达式1的值 + +②如果值为true就执行语句体1;如果值为false就计算关系表达式2的值 + +③如果值为true就执行语句体2;如果值为false就计算关系表达式3的值 + +④… + +⑤如果没有任何关系表达式为true,就执行语句体n+1。 + +```java +//定义一个在0~100之间的变量a, 90~100优秀,80~89良好,70~79中等,60~69及格,0~59请努力加油! +public class Demo3If { + public static void main(String[] args){ + int score = 65; + if(score >= 90 && score <= 100){ + System.out.println("优秀"); + }else if (score >= 80 && score <= 89){ + System.out.println("良好"); + }else if (score >= 70 && score <= 79){ + System.out.println("中等"); + }else if (score >= 60 && score <= 69){ + System.out.println("及格"); + }else if (score >= 0 && score <= 59){ + System.out.println("请努力加油"); + }else{ + System.out.println("成绩有误!"); + } + } +} +``` + +### 作业 + +```java +import java.util.Scanner; +//if语句格式 +//中国足球队吊打日本鬼子队足球队的比分 +public class bifen { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入中国队的分数"); + int China = sc.nextInt(); + System.out.println("请输入日本队的分数"); + int japan = sc.nextInt(); + + if(China<=japan){ + System.out.println("还需努力。"); + } else if(China-japan>20){ + System.out.println("国家奖励运动员全球游"); + } else if(China-japan>=10){ + System.out.println("国家奖励运动员全国游。"); + } else if(China-japan>0){ + System.out.println("国家奖励运动员一顿大餐。"); + } + } +} +``` + +```java +import java.util.Scanner; +//短路逻辑运算符格式 +public class duanluhuo { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入两位整数A"); + int a = sc.nextInt(); + System.out.println("请输入两位整数B"); + int b = sc.nextInt(); + double c = a+b; + int as = a/10%10; + int ag = a%10; + int bs = b/10%10; + int bg = b%10; + System.out.println("------------------"); + if (as%3==0 || ag%3==0){ + System.out.println("true"); + }else if (bs%3==0 || bg%3==0){ + System.out.println("false"); + }else if (c%3==0){ + System.out.println("true"); + }else{ + System.out.println("false"); + } + } +} +``` + +```java +import java.util.Scanner; +//5.身高是具有遗传性的,子女的身高和父母的身高有一定的关系。假定,父母和子女的身高遗传关系如下: +// +//> 儿子身高(厘米)=(父亲身高+母亲身高) ×1.08÷2 +//> +//> 女儿身高(厘米)=(父亲身高×0.923+母亲身高) ÷2 +//> +//> 现有父亲身高177CM,母亲身高165CM。求子女身高分别预计为多少?【使用变量的定义和算术运算符完成本题】 +public class height { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入父亲身高"); + float F = sc.nextFloat(); + System.out.println("请输入母亲身高"); + float M = sc.nextFloat(); + + System.out.println("儿子身高:"+(F+M)*1.08/2); + System.out.println("女儿身高:"+(F*0.923+M)/2); + } +} +``` + +```java +import java.util.Scanner; +//三元运算符格式 +//3.利用三元运算符求任意三个数中最大者 【三元】 +public class sanyuanyunsuanfu { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入数据A"); + int a = sc.nextInt(); + System.out.println("请输入数据B"); + int b = sc.nextInt(); + System.out.println("请输入数据C"); + int c = sc.nextInt(); + + int E = a>b?a:b; + int F = E>c?E:c; + System.out.println("最大值为:"+F); + } +} +``` + +```java +import java.util.Scanner; + +public class youhui { + //小明想在食堂打包一份午饭,商家的优惠方式如下:鱼香肉丝单点24元,油炸花生米单点8元, + // 米饭单点3元。订单满30元8折优惠。鱼香肉丝优惠价16元,但是优惠价和折扣不能同时使用。 + // 那么这个小伙要点这三样东西,最少要花多少钱? + // 【使用算术运算符、赋值运算符和三元运算符联合完成本题】 + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("米饭单点金额"); + int a = sc.nextInt(); + System.out.println("鱼香肉丝单点金额"); + int b = sc.nextInt(); + System.out.println("油炸花生米单点金额"); + int c = sc.nextInt(); + System.out.println("鱼香肉丝优惠金额"); + int e = sc.nextInt(); + double f=e+b+c;//27 + double g=(a+b)*0.8+c;//28.6 + double h=(a+b+c)*0.8;//28 + double ss=f>g?g:f; + double dd=ss>h?h:ss; + System.out.println("要点这3个东西,最少要花"+dd+"块。"); + } +} +``` + +```java +import java.util.Scanner; +//红茶妹妹有21元钱,她攒了几天钱之后自己的钱比原来的两倍还多三块。绿茶妹妹有24元钱,她攒了几天钱之后自己的钱正好是原来的两倍。 +// +//- 那么红茶和绿茶现在的钱一样多,请问对么?【使用赋值运算符和算术运算符计算各自的钱,使用比较运算符对比大小】 +public class yunsuanfu { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入红茶妹妹的金额"); + int hc = sc.nextInt(); + System.out.println("请输入绿茶妹妹的金额"); + int lc = sc.nextInt(); + double A =(hc*2+3); + double B =(lc*2); + + System.out.println(hc==lc); + if (A==B){ + System.out.println("对的"); + } + else if (A>B){ + System.out.println("绿茶多"); + } + else if (A 儿子身高(厘米)=(父亲身高+母亲身高) ×1.08÷2 + > + > 女儿身高(厘米)=(父亲身高×0.923+母亲身高) ÷2 + > + > 现有父亲身高177CM,母亲身高165CM。求子女身高分别预计为多少?【使用变量的定义和算术运算符完成本题】 + +5. 红茶妹妹有21元钱,她攒了几天钱之后自己的钱比原来的两倍还多三块。绿茶妹妹有24元钱,她攒了几天钱之后自己的钱正好是原来的两倍。 + + - 那么红茶和绿茶现在的钱一样多,请问对么?【使用赋值运算符和算术运算符计算各自的钱,使用比较运算符对比大小】 + +6. 小明想在食堂打包一份午饭,商家的优惠方式如下:鱼香肉丝单点24元,油炸花生米单点8元,米饭单点3元。订单满30元8折优惠。鱼香肉丝优惠价16元,但是优惠价和折扣不能同时使用。那么这个小伙要点这三样东西,最少要花多少钱?【使用算术运算符、赋值运算符和三元运算符联合完成本题】 + +7. 直接写出答案。 对于以下,有int x = 5, y = 6, z; + + 题目1:z = ++x + y++; + + 题目2:z = ++x + x++; + + 题目3:x = ++x + x++; + + 题目4:z = x > y ? ++x : y++; + + 8. ```java + int a =10; + sout(a+"Hello");// 输入了什么 + ``` + + 9. + + + + + + + + + + +