From bf4336c6981f492f4113b4a91665188f39b4aea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BD=B3=E6=B3=BD?= <1097559914@qq.com> Date: Sun, 4 Dec 2022 20:18:02 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\222\214switch\350\257\255\345\217\245.md" | 237 ++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 "02 \346\236\227\344\275\263\346\263\275/20221202 \345\255\246\344\271\240if\350\257\255\345\217\245\345\222\214switch\350\257\255\345\217\245.md" diff --git "a/02 \346\236\227\344\275\263\346\263\275/20221202 \345\255\246\344\271\240if\350\257\255\345\217\245\345\222\214switch\350\257\255\345\217\245.md" "b/02 \346\236\227\344\275\263\346\263\275/20221202 \345\255\246\344\271\240if\350\257\255\345\217\245\345\222\214switch\350\257\255\345\217\245.md" new file mode 100644 index 0000000..fa14fe6 --- /dev/null +++ "b/02 \346\236\227\344\275\263\346\263\275/20221202 \345\255\246\344\271\240if\350\257\255\345\217\245\345\222\214switch\350\257\255\345\217\245.md" @@ -0,0 +1,237 @@ +# 20221202 学习if语句和switch语句 + +#### 1、if语句 + +##### 1.1 if语句格式1 + +```java +if(判断条件){ + 语句体1 +}else{ + 语句体2 +}//else否则的意思,前判断条件不成立,执行否则 +``` + +①判断条件如果true,则执行语句体1 + +②判断条件如果flase,则执行语句体2 + +##### 1.2 if语句格式2 + +```java +if(判断条件){ + 语句体1 +}else if (判断条件){ + 语句体2 +} +…… + else{ + 语句体3 + } +``` + +①判断多种条件,可用else if分支来判断。 + +②if else这种分支结构,是互斥的,众多分支中,只能执行一个,只要一个判断条件满足,就不会执行后面。 + +##### 1.3 if语句格式3(嵌套) + +```java +if(判断条件){ + if(判断条件){ + 语句体1 + }else{ + 语句体2 + } + …… +} + else{ + 语句体3 + } +``` + +------ + +#### 2、switch语句 + +##### 2.1 switch使用: + +```java +switch(表达式){ + case 数值1: + 语句体1 + break; + case 数值2: + 语句体2 + break; + …… + default: + 语句体3 + break; +} +``` + +①每行必须有break; + +②switch能做的if也能做,反过来不一定能用 + +③switch只能判断精准的值,if可以判断一个范围 + +------ + +#### 3、知识补充 + +##### 3.1 有关字符串比较 + +有关字符串比较:因为String是引用类型,不能直接用==来判断。 + +用于String判断是否相等,用equals,例如:a.equals(b)就是比较a和b是否相等 + +##### 3.2 char在扫描器的使用 + +例:char n = sc.next() . charAt(0); + +ps.计算机(内存)通常以0计数开始。 + +------ + +#### 4、作业(书P86,练习5,拓展练习) + +##### 4.1 练习5:某市出租车3km起步价和计费方式:夏利3元,3km以外,每公里2.1元、富康4元,3km以外,每公里2.4元、桑塔纳5元,3km以外,每公里2.7元 + +```java +import java.util.Scanner; + +public class D2 { + public static void main(String[] args) { + double jg = 0; + Scanner sc = new Scanner(System.in); + System.out.println("你乘坐的出租车类型:"); + String cx = sc.next(); + System.out.println("你所乘坐公里数:"); + double gl = sc.nextDouble(); + switch (cx){ + case "夏利": + if (gl > 3){ + jg = (gl - 3)*2.1+3; + }else { + jg = 3; + } + break; + case "富康": + if (gl > 3){ + jg = (gl - 3)*2.4+4; + }else { + jg = 4; + } + break; + case "桑塔纳": + if (gl > 3){ + jg = (gl - 3)*2.7+5; + }else { + jg = 5; + } + break; + } + System.out.println("你所乘坐的是:" + cx + " 你所行驶的公里数:" + gl + " 你需要支付的费用:" + jg ); + } +} +``` + +4.2拓展1:使用switch和if语句算出今天是今年的第几天 + +```java +import java.util.Scanner; + +public class D3 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in ); + System.out.println("请输入当前年份:"); + int y = sc.nextInt(); + System.out.println("请输入当前月份:"); + int m = sc.nextInt(); + System.out.println("请输入当前日子:"); + int d = sc.nextInt(); + int day = 0; + switch (m){ + case 12: + day += 30; + case 11: + day += 31; + case 10: + day += 30; + case 9: + day += 31; + case 8: + day += 31; + case 7: + day += 30; + case 6: + day += 31; + case 5: + day += 30; + case 4: + day += 31; + case 3: + if (y % 4 == 0 && y % 100 !=0 | y%400 == 0 ){ + day += 29; + }else { + day += 28; + } + case 2: + day += 31; + case 1: + day += d; + } + System.out.println("你所输入的日期是:"+y+"年"+m+"月"+d+"日" + " 是今年的第" + day + "天"); + } +} +``` + +4.3拓展2:用户输入一个字符,判断字符是不是字母,如果是字母判断该字母是声母还是韵母,是大写还是小写,不是字母输出“你输入的字符不是字母”: + +```java +import java.util.Scanner; + +public class D4 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("你输入一个字母:"); + char a = sc.next().charAt(0); + //字符对应的ASCII码 + //A =65 Z =90 + //a =97 z =122 + if (a>64 && a<91 || a>96 && a<123){ + System.out.println(a + "是字母"); + if (a>64 && a<91){ + System.out.println(a + "是大写字母"); + }else if (a>96 && a<123){ + System.out.println(a + "是小写字母"); + } + + switch (a){ + case 'a': + case 'e': + case 'i': + case 'o': + case 'u': + case 'v': + case 'A': + case 'E': + case 'I': + case 'O': + case 'U': + case 'V': + System.out.println(a + "是韵母"); + break; + default: + System.out.println(a + "是声母"); + } + }else{ + System.out.println("你输入的字符不是字母"); + } + + } +} +``` + -- Gitee From 0da6787a17065d07abd677c0a9c2abd2116ad195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BD=B3=E6=B3=BD?= <1097559914@qq.com> Date: Wed, 7 Dec 2022 17:35:07 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...257\255\345\217\245 for while do while.md" | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 "02 \346\236\227\344\275\263\346\263\275/20221206 \345\255\246\344\271\240\345\276\252\347\216\257\350\257\255\345\217\245 for while do while.md" diff --git "a/02 \346\236\227\344\275\263\346\263\275/20221206 \345\255\246\344\271\240\345\276\252\347\216\257\350\257\255\345\217\245 for while do while.md" "b/02 \346\236\227\344\275\263\346\263\275/20221206 \345\255\246\344\271\240\345\276\252\347\216\257\350\257\255\345\217\245 for while do while.md" new file mode 100644 index 0000000..0e7eaa3 --- /dev/null +++ "b/02 \346\236\227\344\275\263\346\263\275/20221206 \345\255\246\344\271\240\345\276\252\347\216\257\350\257\255\345\217\245 for while do while.md" @@ -0,0 +1,202 @@ +# 20221206 学习循环语句 for while do while + +#### 1、补充 + +扫描器快捷创建:new Scanner(System.in).var + +#### 2、for循环 + +##### 2.1、for循环格式: + +```java +for (初始化语句;条件判断语句;条件控制语句) { + 循环体语句; +} +``` + +​ 格式说明: + +​ 初始化语句:用于循环刚开始的初始值 + +​ 判断语句:表示循环反复执行的条件,判断循环能不能一直执行下去 + +​ 条件控制语句:用于表示循环每次变化内容,控制循环是否能执行下去 + +​ 循环体:用于循环反复执行的事情 + +##### 2.2、for循环实例: + +水仙花数: + +```java +public class D1 { +public static void main(String[] args) { + //输出所有的水仙花数必然要使用到循环,遍历所有的三位数,三位数从100开始,到999结 +束 + for(int i=100; i<1000; i++) { + //在计算之前获取三位数中每个位上的值 + int ge = i%10; + int shi = i/10%10; + int bai = i/10/10%10; + //判定条件是将三位数中的每个数值取出来,计算立方和后与原始数字比较是否相等 + if(ge*ge*ge + shi*shi*shi + bai*bai*bai == i) { + //输出满足条件的数字就是水仙花数 + System.out.println(i); + } + } +} +} + +``` + +##### 2.3、每行打印两个水仙花数: + +```java +public class Demo6For { + +需求:在控制台输出所有的“水仙花数”,要求每行打印2个 +public static void main(String[] args){ +// 1. 定义变量count,用于保存“打印过”的数量,初始值为0 + int count = 0; + for(int i = 100; i <= 999; i++){ + int ge = i % 10; + int shi = i / 10 % 10; + int bai = i / 10 / 10 % 10; + if( (ge*ge*ge + shi*shi*shi + bai*bai*bai) == i){ + // 2. 在判定和打印水仙花数的过程中,拼接空格, 但不换行,并在打印后让 + //count变量+1,记录打印过的数量 + System.out.print(i + " "); + count++; + // 3. 在每一次count变量+1后,判断是否到达了2的倍数,是的话,换行 + if(count % 2 == 0){ + System.out.println(); + } + } + } +} +} + +``` + +#### 3、while循环语句 + +##### 3.1、while循环格式: + +```java +初始化语句; +while (条件判断语句) { + 循环体语句; + 条件控制语句; +} +``` + +3.2、while循环的例子: + +```java +public class WhileDemo { +public static void main(String[] args) { + //需求:在控制台输出5次"HelloWorld" + //while循环实现 + int j = 1; + while(j<=5) { + System.out.println("HelloWorld"); + j++; + } +} +} +``` + +#### 4、do while循环: + +##### 4.1、do while循环的使用: + +```java +初始化语句; +do { + 循环体语句; + 条件控制语句; +}while(条件判断语句); +``` + +4.2、do while循环的例子: + +```java +public class D4 { +public static void main(String[] args) { + //需求:在控制台输出5次"HelloWorld" + //do...while循环实现 + int j = 1; + do { + System.out.println("HelloWorld"); + j++; + }while(j<=5); +} +} + +``` + +#### 5、注意事项: + +##### ①三种循环的区别 + + for循环和while循环先判断条件是否成立,然后决定是否执行循环体(先判断后执行) + +do...while循环先执行一次循环体,然后判断条件是否成立,是否继续执行循环体(先执行后 判断) + +##### ②for循环和while的区别 + +条件控制语句所控制的自增变量,因为归属for循环的语法结构中,在for循环结束后,就不能 再次被访问到了 + +条件控制语句所控制的自增变量,对于while循环来说不归属其语法结构中,在while循环结束 后,该变量还可以继续使用 + +##### ③死循环(无限循环)的三种格式 + +```java +for(;;){} ; +while(true){} +do {} while(true); + +``` + +##### 6、跳转控制语句 + +##### 6.1、break 结束循环的使用: + +```java +public class D1 { + //需求: 模拟20岁工作到80岁, 60岁退休. + public static void main(String[] args) { + for(int i = 20; i <= 80; i++){ + if(i == 60){ + System.out.println("您的年龄已经到达60岁,你可以退休了"); + break; + } + System.out.println("你现在" + i +"岁正在上班"); + } + + } +} +``` + +##### 6.2、continue继续下一个循环的使用: + +```java +public class D2 { + //模拟电梯上下,1-25层,4 14 24不停 + public static void main(String[] args) { + for(int i=1; i<=25 ; i++){ + if (i==4){ + continue; + } + if (i==14) { + continue; + } + if (i==24){ + continue; + } + System.out.println("你已经到达" + i +"层"); + } + } + } +``` + -- Gitee From a6976bbad09c1963aedc768290d85ded4ec12b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BD=B3=E6=B3=BD?= <1097559914@qq.com> Date: Thu, 8 Dec 2022 22:09:10 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\346\225\260 \346\225\260\347\273\204.md" | 186 ++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 "02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\204.md" diff --git "a/02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\204.md" "b/02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\204.md" new file mode 100644 index 0000000..3d49a65 --- /dev/null +++ "b/02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\204.md" @@ -0,0 +1,186 @@ +# 20221208 学习随机数 数组 + +##### 补充: + +​ 标记:给while作个标记,取名flag,用在循环无法退出做标记,不冲突。 + +例如:flag:while + +## 1、随机数 + +##### 1.1、生成随机数格式 + +```java +Random ran = new Random();//随机数生成 +int a = ran.nextInt(10); //代表[0,10) 0~9,随机数从0开始。 + +//若要从1~15 则表示为 +int b = ran.nextInt(15)=1; +``` + +## 2、数组 + +##### 2.1、数组的格式 + +​ 数组是可存储多个数据的组合 + +格式如下: + +```java +int[] arr={……}; //数组格式,数组必须初始化 +``` + +##### 2.2、数组元素访问 + +①索引从0开始 + +②格式: + +```java +arr [索引] +``` + +③获取数组的长度: + +```java +int a= arr.length;//length为长度 +``` + +##### 2.3、数组遍历 + +就是将数组中的每个元素分别获取出来,就是遍历。遍历也是数组操作中的基石。 + +①从头到尾输出: + +```java +int[] arr={……} +for(int i=0 ;i max){ + max=arr[x]; + } +} +System.out.println(max); +``` + +④元素打乱: + +```java +import java.util.Arrays; +import java.util.Random; + +public class D1 { + public static void main(String[] args) { + int[] arr = {1, 4, 5, 7, 8, 9}; + System.out.println(Arrays.toString(arr));//先将数组打印出来 + //创建随机数 + Random ran = new Random(); + //定义两个数据类型,分别赋值不同 + int a = ran.nextInt(arr.length); + int b = ran.nextInt(arr.length); + //交换 定义一个新的变量,用于交换 + int c = arr[a]; + arr[a] = arr[b]; + arr[b] = c; + //打乱后输出 + System.out.println(Arrays.toString(arr)); + } +} + +``` + +## 3、作业 + +##### 3.1、猜数字 + +```java +import java.util.Random; +import java.util.Scanner; + +public class D2 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + Random ran = new Random(); + int a = ran.nextInt(90)+10; + int js = 0 ; + flag:while (true){ + System.out.println("请输入你所猜的数字(10~99):"); + int csz = sc.nextInt(); + if (csz>a){ + System.out.println("猜大,重来!"); + }else if(cszmax){ + max = arr[i]; + } + } + System.out.println("此组最大的数是:" + max); + + } +} +``` \ No newline at end of file -- Gitee From 58734f66cabd68f86bbcb8f2f97323c5cd50ac1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BD=B3=E6=B3=BD?= <1097559914@qq.com> Date: Sun, 11 Dec 2022 23:48:22 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...73\20420221209\346\233\264\346\226\260.md" | 62 ++++++++++++++++++- .../20221209 \346\225\260\347\273\204.md" | 50 +++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) rename "02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\204.md" => "02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\20420221209\346\233\264\346\226\260.md" (75%) create mode 100644 "02 \346\236\227\344\275\263\346\263\275/20221209 \346\225\260\347\273\204.md" diff --git "a/02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\204.md" "b/02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\20420221209\346\233\264\346\226\260.md" similarity index 75% rename from "02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\204.md" rename to "02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\20420221209\346\233\264\346\226\260.md" index 3d49a65..a57340b 100644 --- "a/02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\204.md" +++ "b/02 \346\236\227\344\275\263\346\263\275/20221208 \345\255\246\344\271\240\351\232\217\346\234\272\346\225\260 \346\225\260\347\273\20420221209\346\233\264\346\226\260.md" @@ -24,12 +24,24 @@ int b = ran.nextInt(15)=1; ​ 数组是可存储多个数据的组合 -格式如下: +1. 静态初始化格式如下: + + ```java + int[] arr={……}; //数组格式,数组必须初始化 + ``` + + + +2. 动态初始化格式如下: ```java -int[] arr={……}; //数组格式,数组必须初始化 +int[] arr =new int[6]; //6为长度 ``` +​ + +​ 注意:两种初始化方式为独立的,不能混用。 + ##### 2.2、数组元素访问 ①索引从0开始 @@ -111,6 +123,52 @@ public class D1 { ``` +⑤foreach(没有索引): + +```java +for(int a:num){ + sout(a+""); +} +``` + +此种方法用在没有定义哪个索引上的 + +##### 2.4、空指针: + +​ null为空值 + +但是也经常出现异常 + +如: + +```java +public class ArrayDemo { + public static void main(String[] args) { + int[] arr = new int[3]; + + //把null赋值给数组 + arr = null; + System.out.println(arr[0]); + } +} +``` + +- arr = null 这行代码,意味着变量arr将不会在保存数组的内存地址,也就不允许再操作数组了,因此运行的时候会抛出 NullPointerException 空指针异常。在开发中,空指针异常是不能出现的,一旦出现了,就必须要修改我们编写的代码。 + +- 解决方案 + + 给数组一个真正的堆内存空间引用即可! + +##### 2.5索引越界异常:访问了不存在的索引 + +```java +int[] a = {1}; +sout(a[1]);// 本意是想输出第1个元素,但数组是从0开始的,这里的1表示第2个, +// 但数组里并没有第2个,所以会产生索引越界的异常 +``` + + + ## 3、作业 ##### 3.1、猜数字 diff --git "a/02 \346\236\227\344\275\263\346\263\275/20221209 \346\225\260\347\273\204.md" "b/02 \346\236\227\344\275\263\346\263\275/20221209 \346\225\260\347\273\204.md" new file mode 100644 index 0000000..05fcb95 --- /dev/null +++ "b/02 \346\236\227\344\275\263\346\263\275/20221209 \346\225\260\347\273\204.md" @@ -0,0 +1,50 @@ +# 数组作业 + +ps.数组和随机数小结在:[20221208 学习随机数 数组20221209更新](./20221208 学习随机数 数组20221209更新.md) + +1、闽大举行选美比赛,男生参赛,10个女生当评委,定义一个数组,存放评分,用随机数模拟打分的过程,用程序算出选手的最后得分【去掉一个最高分,再去掉一个最低分,用剩下的分数求平均值】, + +```java +package 数组作业1; + +import java.util.Random; + +public class D1 { + public static void main(String[] args) { + //闽大举行选美比赛,男生参赛,10个女生当评委,定义一个数组,存放评分,用随机数模拟打分的过程,用程序算出选手的最后得分【去掉一个最高分,再去掉一个最低分,用剩下的分数求平均值】, + int[] girl = new int[10]; + Random ran = new Random(); + for (int i = 0 ; i < girl.length ; i ++){ + girl[i] = ran.nextInt(101); + } + System.out.println("十位评委评分如下:"); + for (int num:girl) { + System.out.print(num+" "); + } + //定义最大值 + int max = girl[0]; + for (int j = 0 ; j < girl.length ; j++){ + if (girl[j] > max){ + max = girl[j]; + } + } + System.out.println("\n评委中最高分是:" + max); + //定义最小值 + int min = girl[0]; + for ( int j = 0 ; j< girl.length ; j++){ + if (girl[j] Date: Tue, 13 Dec 2022 15:57:41 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\350\264\271\344\275\234\344\270\232.md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "02 \346\236\227\344\275\263\346\263\275/20221213 \344\271\230\346\263\225\350\241\250\345\222\214\347\207\203\346\260\224\350\264\271\344\275\234\344\270\232.md" diff --git "a/02 \346\236\227\344\275\263\346\263\275/20221213 \344\271\230\346\263\225\350\241\250\345\222\214\347\207\203\346\260\224\350\264\271\344\275\234\344\270\232.md" "b/02 \346\236\227\344\275\263\346\263\275/20221213 \344\271\230\346\263\225\350\241\250\345\222\214\347\207\203\346\260\224\350\264\271\344\275\234\344\270\232.md" new file mode 100644 index 0000000..a03e58f --- /dev/null +++ "b/02 \346\236\227\344\275\263\346\263\275/20221213 \344\271\230\346\263\225\350\241\250\345\222\214\347\207\203\346\260\224\350\264\271\344\275\234\344\270\232.md" @@ -0,0 +1,42 @@ +# 20221213 乘法表和燃气费作业 + +1、倒序输出乘法口诀,9到1 + +```java +package 作业1; + +public class D3 { + public static void main(String[] args) { + //倒序输出乘法口诀,9到1 + for (int i = 9 ; i >= 1 ; i--){ + for (int j = i ; j >= 1 ; j--){ + System.out.print(i + "*" + j + "=" + i*j + "\t"); + + } + System.out.println(); + } + } +} +``` + +2、计算燃气,一档阶梯(0-240:3.375 元/方);二档阶梯(241-360:405元/方);三档阶梯(361-99999999:5.06元/方);若客户充值100元燃气费,花费445.40元,那么他用二档和三档燃气分别交了多少? + +```java +package 数组作业1; + +public class D4 { + public static void main(String[] args) { + //计算燃气,一档阶梯(0-240:3.375 元/方); + // 二档阶梯(241-360:405元/方); + // 三档阶梯(361-99999999:5.06元/方); + // 若客户充值100元燃气费,花费445.40元,那么他用二档和三档燃气分别交了多少? + for (int i = 1 ; i <= 100 ; i++){ + if (i * 4.05 + (100 - i) * 5.06 == 445.4){ + System.out.println("二档缴费了:" + i + "方"); + System.out.println("二档缴费了:" + (100-i) + "方"); + } + } + } +} +``` + -- Gitee