diff --git "a/43 \351\237\251\346\226\207\346\235\260/20221203 javaSwitch.md" "b/43 \351\237\251\346\226\207\346\235\260/20221203 javaSwitch.md" new file mode 100644 index 0000000000000000000000000000000000000000..903a7fa7812c2e12344fce7c2ddbdc54aef9677a --- /dev/null +++ "b/43 \351\237\251\346\226\207\346\235\260/20221203 javaSwitch.md" @@ -0,0 +1,129 @@ +# 作业 + +~~~java +package yiyi; +//5.某市不同车牌的出租车3千米的起步价和计费分别为:夏利3元,3千米以外,2.1/千米以外, +//富康4元,3千米以外,2.4/千米;桑塔纳5元,3千米以外,2.7/千米。编程实现从键盘 +//输入乘车的车型及行车千米数,输出对应车费。 +import java.sql.SQLOutput; +import java.util.Scanner; + +public class Y1 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("请输入车型"); + char cx =sc.next().charAt(0); + System.out.println("请输入千米数"); + double a =sc.nextDouble(); + double b =0; + switch (cx){ + case '1': + if(a>3){ + b=(a-3)*2.1+3; + }else { + b=3; + } + break; + case '2': + if(a>3){ + b=(a-3)*2.4+4; + }else { + b=4; + } + break; + case '3': + if (a>3){ + b=(a-3)*2.7+5; + }else { + b=5; + } + break; + default: + System.out.println("请输入正确的车型"); + } + System.out.println("应付车费:"+b+"块"); + } +} + + +~~~ + +~~~java +package yiyi; + +import java.util.Scanner; + +public class Y2 { + public static void main(String[] args) { + //1.使用switch和if语句算出今天是今年第几天(提示:以3月3日为例,应该先把前两个月的天数加起来, +// 然后再加上3天即为本年的第几天:需要考虑闰年的情况,如果输入的年份是闰年且输入的月份大于或等于3, +// 需要多加一天)。 + class D2 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("请输入年份:"); + int a1 = sc.nextInt(); + System.out.println("请输入月份:"); + int a2 = sc.nextInt(); + System.out.println("请输入日份:"); + int a3 = sc.nextInt(); + //定义变量 + int b1 =0; + int b2 =31; + int b3 =30; + int ts =0; + if (a1 % 4 == 0 && a1 % 100 == 0 || a1 %400==0){ + ts =29; + if(a1>=3){ + ts=30; + } + else { + ts=28; + } + if(a2>1){ + int sh =a2-1; + switch (sh){ + case 2: + b1=a3+b2+ts; + break; + case 3: + b1=2*a3+b2+ts; + break; + case 4: + b1=2*a3+sh+b3+b2+ts; + break; + case 5: + b1=3*a3+sh+b3+b2+ts; + break; + case 6: + b1=3*a2+2*sh+b2+ts; + break; + case 7: + b1=4*a2+3*sh+b2+ts; + case 8: + b1=4*a2+3*sh+b2+ts; + break; + case 9: + b1=5*a2+3*sh+b2+ts; + break; + case 10: + b1=5*a2+4*sh+b2+ts; + break; + case 11: + b1=6*a2+24*sh+b2+ts; + break; + + } + + }else{ + b1=a3; + } + System.out.println(a1+"年"+b2+"月"+a3+"日期"+"是今年的第"+b1+"天"); + } + } + } + } +} + +~~~ +