From 2693fe50432267c961e765c06ada6e89e0bf5c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=87=E9=94=8B?= <2069827762@qq.com> Date: Thu, 1 Dec 2022 22:45:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...03\350\277\220\347\256\227\347\254\246.md" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "07 \345\210\230\346\226\207\351\224\213/20221201 java\344\270\211\345\205\203\350\277\220\347\256\227\347\254\246.md" diff --git "a/07 \345\210\230\346\226\207\351\224\213/20221201 java\344\270\211\345\205\203\350\277\220\347\256\227\347\254\246.md" "b/07 \345\210\230\346\226\207\351\224\213/20221201 java\344\270\211\345\205\203\350\277\220\347\256\227\347\254\246.md" new file mode 100644 index 0000000..8b3dbdb --- /dev/null +++ "b/07 \345\210\230\346\226\207\351\224\213/20221201 java\344\270\211\345\205\203\350\277\220\347\256\227\347\254\246.md" @@ -0,0 +1,67 @@ +# 笔记 + +三元运算符语法格式: + +解释:问号前面的位置是判断的条件,判断结果为boolean型,为true时调用表达式1,为false时调用表 达式2。其逻辑为:如果条件表达式成立或者满足则执行表达式1,否则执行第二个。 + +举例: + +int a = 10; + + int b = 20; + +int c = a > b ? a : b; // 判断 a>b 是否为真,如果为真取a的值,如果为假,取b的值. + + + +3.利用三元运算符求任意三个数中最大者 【三元】 + +```Java +public class ternary { + public static void main(String[] args) { + Scanner df = new Scanner(System.in); + System.out.println("请输入第一个数"); + double one = df.nextDouble(); + System.out.println("请输入第二个数"); + double two = df.nextDouble(); + System.out.println("请输入第三个数"); + double three = df.nextDouble(); + + double w = one > two ? one : two; + double s = w > three ? w : three; + System.out.println("最大数:" + s); + } +} +``` + +4.足球 + +```java +public class football { + public static void main(String[] args) { + Scanner abc = new Scanner(System.in); + System.out.println("输入中国男足比分:"); + int China = abc.nextInt(); + System.out.println("输入谢先君的比分:"); + int Japanese = abc.nextInt(); + if (China<0 | China>10 && Japanese<0 | Japanese>10) { + System.out.println("挂哥"); + }else if(China>=7){ + System.out.println("中国大大滴哟西 "); + }else if (China>=4){ + System.out.println("中国滴哟西 "); + }else if (China<2){ + System.out.println("中国大大滴再接再厉 "); + } + if (Japanese>=7){ + System.out.println("谢先君你的良心大大滴坏"); + }else if (Japanese>=4) { + System.out.println("谢先滴八嘎"); + }else if (Japanese<2){ + System.out.println("谢先滴不错滴干活"); + } + + + } +} +``` \ No newline at end of file -- Gitee