From 3a88efe2541c06bbd40ba5b8bf245e8555dcb0c5 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Wed, 14 Jan 2026 16:50:18 +0800 Subject: [PATCH] =?UTF-8?q?day03-=E6=B5=81=E7=A8=8B=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5-=E5=88=A4=E6=96=AD=E6=B5=81=E7=A8=8B-if?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=B8=89=E7=9A=84=E4=BD=BF=E7=94=A8=E5=92=8C?= =?UTF-8?q?=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day03/src/com/inmind/if01/Demo03.java | 71 +++++++++++++++++++++++++++ day03/src/com/inmind/if01/Test04.java | 11 +++++ 2 files changed, 82 insertions(+) create mode 100644 day03/src/com/inmind/if01/Demo03.java create mode 100644 day03/src/com/inmind/if01/Test04.java diff --git a/day03/src/com/inmind/if01/Demo03.java b/day03/src/com/inmind/if01/Demo03.java new file mode 100644 index 0000000..4822dfc --- /dev/null +++ b/day03/src/com/inmind/if01/Demo03.java @@ -0,0 +1,71 @@ +package com.inmind.if01; +/* +if格式三: +if(判断条件1){ + 语句1; +}else if(判断条件2){ + 语句2; +}else if(判断条件3){ + 语句3; +}.... +else{ + 语句n; +} + +执行顺序:先执行判断条件1,判断条件必须是布尔型的结果, + 如果为true,就执行大括号语句1,这时结束了整个if语句, + 如果为false就直接跳过if后面大括号中的语句1继续向下判断判断条件2 + 如果为true,就执行大括号语句2,这时结束了整个if语句 + 如果为false就直接跳过if后面大括号中的语句2继续向下判断.... + 最终如果所有的判断条件都为false,那么就直接执行else后面的语句n + +注意:格式三,肯定会执行一个语句,但是也永远都只会执行一个语句; + +*/ + +/* + x和y的关系满足如下: + x>=3 y = 2x + 1; + -1<=x<3 y = 2x; + x<-1 y = 2x – 1; + 根据给定的x的值,计算出y的值并输出。 + */ +public class Demo03 { + public static void main(String[] args) { + //定义一个x的值 + int x = -2; + int y;//此时y的值不确定,先定义后赋值 + + //if-else if -else if - else的格式三实现多条件判断 + if (x >= 3) { + y = 2 * x + 1; + } else if (x >= -1 && x < 3) { + y = 2 * x; + } else{//除去上面的2种情况,剩下的都满足x<-1 + y = 2 * x - 1; + } + + System.out.println(y); + System.out.println("程序结束"); + } + + + //if-格式三的使用 + public static void ifMethod3() { + //定义一个x的值 + int x = -2; + int y;//此时y的值不确定,先定义后赋值 + + //if-else if -else if - else的格式三实现多条件判断 + if (x >= 3) { + y = 2 * x + 1; + } else if (x >= -1 && x < 3) { + y = 2 * x; + } else{//除去上面的2种情况,剩下的都满足x<-1 + y = 2 * x - 1; + } + + System.out.println(y); + System.out.println("程序结束"); + } +} diff --git a/day03/src/com/inmind/if01/Test04.java b/day03/src/com/inmind/if01/Test04.java new file mode 100644 index 0000000..b4804d1 --- /dev/null +++ b/day03/src/com/inmind/if01/Test04.java @@ -0,0 +1,11 @@ +package com.inmind.if01; +/* +指定考试成绩,判断学生等级 +90-100 优秀 +80-89 好 +70-79 良 +60-69 及格 +60以下 不及格 + */ +public class Test04 { +}