From 3237049e8bd841ba6fe2950815e58a5feba60431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=BF=97=E9=B9=8F?= <326806914@qq.com> Date: Wed, 14 Dec 2022 18:54:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022 12.13 \344\275\234\344\270\232.md" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "10 \346\234\261\345\277\227\351\271\217/2022 12.13 \344\275\234\344\270\232.md" diff --git "a/10 \346\234\261\345\277\227\351\271\217/2022 12.13 \344\275\234\344\270\232.md" "b/10 \346\234\261\345\277\227\351\271\217/2022 12.13 \344\275\234\344\270\232.md" new file mode 100644 index 0000000..10d5dbe --- /dev/null +++ "b/10 \346\234\261\345\277\227\351\271\217/2022 12.13 \344\275\234\344\270\232.md" @@ -0,0 +1,30 @@ +作业 + +```java +作业,1,倒序输出乘法口诀,9到1 +public class jj { + public static void main(String[] args) { + for (int i=9;i>=1 +;i--){ + for (int J=9;J>=i;J--){ + System.out.println(J+"*"+i+"="+J*i+" "); + } + System.out.println(); + } + } +} + + + +public class A11 { + public static void main(String[] args) { + for (int x=1;x<=100;x++){ + if (x *4.05 + (100-x) * 5.06 == 445.4){ + System.out.println("第二档是:"+x+"立方,第三档是:"+(100-x)+"立方"); + } + } + } +} +``` + + -- Gitee From 48e3449a8f7324aa3d01e42ad1afe03f12fb3b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=BF=97=E9=B9=8F?= <326806914@qq.com> Date: Fri, 16 Dec 2022 10:33:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2022 12.15java\346\226\271\346\263\225.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "10 \346\234\261\345\277\227\351\271\217/2022 12.15java\346\226\271\346\263\225.md" diff --git "a/10 \346\234\261\345\277\227\351\271\217/2022 12.15java\346\226\271\346\263\225.md" "b/10 \346\234\261\345\277\227\351\271\217/2022 12.15java\346\226\271\346\263\225.md" new file mode 100644 index 0000000..12dfb88 --- /dev/null +++ "b/10 \346\234\261\345\277\227\351\271\217/2022 12.15java\346\226\271\346\263\225.md" @@ -0,0 +1,60 @@ +# 带返回值方法的定义和调用 + +带返回值方法定义和调用(掌握) + +定义格式 + +```java +public static 数据类型 方法名 ( 参数 ) { +return 数据 ; +} +``` + +范例 + +```java +public static boolean isEvenNumber( int number ) { +return true ; +} +public static int getMax( int a, int b ) { +return 100 ; +} +``` + +作业 + +```java +作业 :. 定义一函数,用于求2个数中的较大数,并将其返回,这2个数字在主函数中由用户输入 +4. 在主函数中从键盘接收X, Y , Z3个数,编写函数计算这3个数的立方和并返回计算结果:S=X3+Y3+Z3 + + + + public static void main(String[] args) { + int k = getMax(1, 2); + System.out.println(k); + } + public static int getMax(int a, int b) { + + return a>b?a:b; + } + } + + + +public class ddd { + public static void main(String[] args) { + System.out.println("请输入三个数"); + Scanner sc = new Scanner(System.in); + int x = sc.nextInt(); + int y = sc.nextInt(); + int z = sc.nextInt(); + double s = (x + y + z) * 3; + System.out.println("立方和等于" + s); + + + + }int +} + + +``` -- Gitee From 5125f7a383d72637f831f05862552eb0d106288a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=BF=97=E9=B9=8F?= <326806914@qq.com> Date: Mon, 19 Dec 2022 21:36:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...75\346\225\260\344\275\234\344\270\232.md" | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 "10 \346\234\261\345\277\227\351\271\217/2022 12 .18 java\345\207\275\346\225\260\344\275\234\344\270\232.md" diff --git "a/10 \346\234\261\345\277\227\351\271\217/2022 12 .18 java\345\207\275\346\225\260\344\275\234\344\270\232.md" "b/10 \346\234\261\345\277\227\351\271\217/2022 12 .18 java\345\207\275\346\225\260\344\275\234\344\270\232.md" new file mode 100644 index 0000000..f62d65f --- /dev/null +++ "b/10 \346\234\261\345\277\227\351\271\217/2022 12 .18 java\345\207\275\346\225\260\344\275\234\344\270\232.md" @@ -0,0 +1,112 @@ +作业 + +编写函数,计算圆的面积和周长,在主函数中接受圆的半径,在自定义函数中计算并输出 + +```java +import java.util.Scanner; + +public class ddd { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("请输入圆的半径"); + int b = scanner.nextInt(); + System.out.println("面积为"+b*3.14); + System.out.println("周长为"+b*2*3.14); + } +} + + + +``` + +在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) + +```java + +import java.util.Arrays; +import java.util.Scanner; + +public class s { + public static void main(String[] args) { + long[] nums = new long[20]; + for (int i = 0; i < 20; i++) { + nums[i] = Math.round(Math.random() * 10); + } + Scanner sc = new Scanner(System.in); + System.out.println("请输入某个数"); + long X = sc.nextLong(); + search(nums,X); +} + public static void search(long[] nums,long X){ + int count=0; + for (int i = 0; i < nums.length; i++) { + if(X==nums[i]){ + count++; + } + } + System.out.println(Arrays.toString(nums)); + + } + } +``` + + + +用自定义函数是实现求某数组元素的和(大小不固定) + +```java +public class jj { + public static void main(String[] args) { + int[] a = {1,2,3}; + x(a); + } + + public static void x(int[] a) { + int s = 0; + for (int i = 0; i < a.length; i++) { + s += a[i]; + } + System.out.println(s); + } +} +``` + + 用户输入整数n,计算1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) + +```java +mport java.util.Scanner; + +public class jj { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入整数n"); + while(true){ + int n = sc.nextInt(); + if(n<1||n>10){ + System.out.println("输入不合法"); + }else{ + int s = a(n); + System.out.println("1到"+n+"的阶乘的和为:"+s); + break; + } + } + } + public static int a(int n){ + int sum = 0; + while(n>0){ + sum= sum+fac(n); + n--; + } + return sum; + } + public static int fac(int num){ + if(num==1){ + return 1; + }else{ + return num*fac(num-1); + } + } +} + + +``` -- Gitee