diff --git "a/05\350\260\242\351\223\226\346\265\251/1126 \350\260\242\351\223\226\346\265\251.md" "b/05 \350\260\242\351\223\226\346\265\251/1126 \350\260\242\351\223\226\346\265\251.md" similarity index 100% rename from "05\350\260\242\351\223\226\346\265\251/1126 \350\260\242\351\223\226\346\265\251.md" rename to "05 \350\260\242\351\223\226\346\265\251/1126 \350\260\242\351\223\226\346\265\251.md" diff --git "a/05\350\260\242\351\223\226\346\265\251/20221129 \350\260\242\351\223\226\346\265\251.md" "b/05 \350\260\242\351\223\226\346\265\251/20221129 \350\260\242\351\223\226\346\265\251.md" similarity index 100% rename from "05\350\260\242\351\223\226\346\265\251/20221129 \350\260\242\351\223\226\346\265\251.md" rename to "05 \350\260\242\351\223\226\346\265\251/20221129 \350\260\242\351\223\226\346\265\251.md" diff --git "a/05 \350\260\242\351\223\226\346\265\251/20221202 if\345\222\214switch.md" "b/05 \350\260\242\351\223\226\346\265\251/20221202 if\345\222\214switch.md" new file mode 100644 index 0000000000000000000000000000000000000000..f08f6aecd0d1b490447d5776229656b02eb2c2db --- /dev/null +++ "b/05 \350\260\242\351\223\226\346\265\251/20221202 if\345\222\214switch.md" @@ -0,0 +1,121 @@ +```java +import java.util.Scanner; + +public class dd1 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("请输入车型"); + String cx= sc.next(); + Scanner km=new Scanner(System.in); + System.out.println("请输入公里"); + int gl= km.nextInt(); + if (gl>3) { + switch (cx) { + case "夏利": + System.out.println((gl - 3) * 2.1 + 3); + break; + case "富康": + System.out.println((gl - 3) * 2.4 + 3); + break; + case "桑塔纳": + System.out.println((gl - 3) * 2.7 + 3); + break; + } + } + else { + switch (cx){ + case"夏利": + System.out.println("3元"); + break; + case"富康": + System.out.println("4元"); + break; + case"桑塔纳": + System.out.println("5元"); + break; + } + } + } +} +``` + +```java +import java.util.Scanner; + +public class DD2 { + public static void main(String[] args) { + Scanner a=new Scanner(System.in); + System.out.println("请输入年"); + int nian=a.nextInt(); + Scanner b=new Scanner(System.in); + System.out.println("请输入月"); + int yue=b.nextInt(); + Scanner c=new Scanner(System.in); + System.out.println("请输入日"); + int ri=a.nextInt(); + int ey; + if(nian % 4==0 &&nian %100!=0||nian%400==0){ + ey=29; + }else ey=28; + + switch (yue){ + case 1: + System.out.println(ri); + break; + case 2: + System.out.println(ri+31); + break; + case 3: + System.out.println(ri+ey+31); + break; + case 4: + System.out.println(ri+ey+31*2); + break; + case 5: + System.out.println(ri+ey+31*2+30); + break; + case 6: + System.out.println(ri+ey+31*3+30); + break; + case 7: + System.out.println(ri+ey+31*3+30*2); + break; + case 8: + System.out.println(ri+ey+31*4+30*2); + break; + case 9: + System.out.println(ri+ey+31*5+30*2); + break; + case 10: + System.out.println(ri+ey+31*5+30*3); + break; + case 11: + System.out.println(ri+ey+31*6+30*3); + break; + case 12: + System.out.println(ri+ey+31*6+30*4); + break; + } + } + +} +``` + +三元运算符 + +~~~java +int a = 10; +int b = 20; +int c = a > b ? a : b; // 判断 a>b 是否为真,如果为真取a的值,如果为假,取b的值 +先执行关系表达式 看结果 是不是执行 如果执行 就执行关系表达式1 否则执行表达式2 +~~~ + +if语句 + +~~~java +格式1: +if (关系表达式) { + 语句体; +} +首先计算关系表达式的值 如果关系表达式的值为true就执行语句体 如果关系表达式的值为false就不执行语句体 继续执行后面的语句内容 +~~~ \ No newline at end of file diff --git "a/05 \350\260\242\351\223\226\346\265\251/20221208 \345\276\252\347\216\257\346\225\260\347\273\204.md" "b/05 \350\260\242\351\223\226\346\265\251/20221208 \345\276\252\347\216\257\346\225\260\347\273\204.md" new file mode 100644 index 0000000000000000000000000000000000000000..e27c17296598f11ffa2e3eac27d04d1e84b5f14f --- /dev/null +++ "b/05 \350\260\242\351\223\226\346\265\251/20221208 \345\276\252\347\216\257\346\225\260\347\273\204.md" @@ -0,0 +1,22 @@ +```java +import java.util.Scanner; + +public class D15 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + + + int[]scores=new int[5]; + + for( int i=0;i<5;i++){ + System.out.println("输入一个数值"); + scores[i]= sc.nextInt(); + } + + + for(int b=0;b<5;b++){ + System.out.println(" "+scores[b]); + } + } +} +``` \ No newline at end of file diff --git "a/05 \350\260\242\351\223\226\346\265\251/20221219\345\207\275\346\225\260.md" "b/05 \350\260\242\351\223\226\346\265\251/20221219\345\207\275\346\225\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..c9bd97b66cec33a0cfb37c280082511a86cc6bc1 --- /dev/null +++ "b/05 \350\260\242\351\223\226\346\265\251/20221219\345\207\275\346\225\260.md" @@ -0,0 +1,49 @@ +~~~java +import java.util.Scanner; + +public class D777 { + public static void main(String[] args) { + Scanner d1 =new Scanner(System.in); + System.out.println("请输入数据"); + int a1= d1.nextInt(); + System.out.println("请输入数据"); + int a2= d1.nextInt(); + int max=max(a1,a2); + System.out.println("最大值为"+max); + } + public static int max(int a1, int a2) { + if(a1>a2) + return a1; + else + return a2; + + } + +} +~~~ + +~~~jav +import java.util.Scanner; + +public class D777 { + public static void main(String[] args) { + Scanner d1 =new Scanner(System.in); + System.out.println("请输入数据"); + int x= d1.nextInt(); + System.out.println("请输入数据"); + int y= d1.nextInt(); + System.out.println("请输入数据"); + int z= d1.nextInt(); + int sum=sum(x,y,z); + System.out.println("三个数的立方是"+ sum); + } + public static int sum(int x, int y,int z) { + int sum=x*x*x+y*y*y+z*z*z; + return sum; + + + } + +} +~~~ + diff --git "a/05\350\260\242\351\223\226\346\265\251/2022121\350\260\242\351\223\226\346\265\251.md" "b/05 \350\260\242\351\223\226\346\265\251/2022121\350\260\242\351\223\226\346\265\251.md" similarity index 100% rename from "05\350\260\242\351\223\226\346\265\251/2022121\350\260\242\351\223\226\346\265\251.md" rename to "05 \350\260\242\351\223\226\346\265\251/2022121\350\260\242\351\223\226\346\265\251.md" diff --git "a/05 \350\260\242\351\223\226\346\265\251/20221220.md" "b/05 \350\260\242\351\223\226\346\265\251/20221220.md" new file mode 100644 index 0000000000000000000000000000000000000000..24ecafd5941d3d5e2686c399dbaca4f366804aaa --- /dev/null +++ "b/05 \350\260\242\351\223\226\346\265\251/20221220.md" @@ -0,0 +1,152 @@ +import java.util.Scanner; +7 + +8 +public class gu { +9 + public static void main(String[] args) { +10 + Scanner sc = new Scanner(System.in); +11 + System.out.println("输入⚪的半径"); +12 + ad(sc.nextDouble(),3.14); +13 + } +14 + public static void ad(double a, double b){ +15 + System.out.println("半径是"+2*b*a); +16 + System.out.println("面积是"+b*a*a); +17 + } +18 + +19 +} +20 +``` +21 + +22 + 在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) +23 + +24 +```java +25 +import java.util.Arrays; +26 +import java.util.Scanner; +27 + +28 +public class shuzu { +29 + public static void main(String[] args) { +30 + long[] num = new long[10]; +31 + for (int i = 0; i < 20; i++) { +32 + num[i] = Math.round(Math.random() * 10); +33 + } +34 + Scanner sc = new Scanner(System.in); +35 + System.out.println("输入一个数"); +36 + long A = sc.nextLong(); +37 + af(num, A); +38 + } +39 + +40 + public static void af(long[] num, long A) { +41 + int count = 0; +42 + for (int i=0;i< num.length;i++){ +43 + if (A==num[i]){ +44 + count++; +45 + } +46 + } +47 + System.out.println(Arrays.toString(num)); +48 + System.out.println("次数是"+count); +49 + } +50 +} +51 +``` +52 + +53 +在主函数中接收10个数存入数组,在自定义函数中,将该数组中的最大值与第一个元素交换,最小值与最后一个元素交换,然后在主函数中输出交换后的数组 +54 + +55 +```java +56 +import java.util.Arrays; +57 + +58 +public class dfas { +59 + public static void main(String[] args) { +60 + int ac[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; +61 + System.out.println(Arrays.toString(ac)); +62 + add(ac); +63 + +64 + } +65 + +66 + public static void add(int brr[]) { +67 + int max = brr[0]; +68 + int x = brr[0]; +69 + +70 + for (int i = 0; i < brr.length; i++) { +71 + if (brr[i] > max) { +72 + max = brr[i]; +73 + } +74 + } +75 + for (int i=0;i< brr.length;i++){ +76 + if (brr[i]==max){ +77 + brr[i]=x; +78 + } +79 + } +80 + brr[0]=max; +81 + System.out.print("["); +8 \ No newline at end of file diff --git "a/05 \350\260\242\351\223\226\346\265\251/2022124 if\345\222\214\345\276\252\347\216\257.md" "b/05 \350\260\242\351\223\226\346\265\251/2022124 if\345\222\214\345\276\252\347\216\257.md" new file mode 100644 index 0000000000000000000000000000000000000000..92abb242cbec38d22c3eb63705fb640e5c2567a6 --- /dev/null +++ "b/05 \350\260\242\351\223\226\346\265\251/2022124 if\345\222\214\345\276\252\347\216\257.md" @@ -0,0 +1,63 @@ +```java +import java.util.Scanner; + +public class D10 { + public static void main(String[] args) { + //2.用户分别输入数 a,数b,让程序实现从a 开始循环到b. + // 输出"有生之年,能看到中国队出线吗?" + int a,b,i; + Scanner sc=new Scanner(System.in); + System.out.println("输出a的数"); + a= sc.nextInt(); + System.out.println("输出b的数"); + b= sc.nextInt(); + if (a>b){ + for (i=0;inum){ + System.out.println("你猜的数字太大了"); + } else if (shuru=2&&count<=6) { + System.out.println("你一点点聪明"); + }else{ + System.out.println("你真蠢"); + } + } +} +``` + +# 笔记: \ No newline at end of file