From c89f9a6e23f11332beca3ba2400f9bfaace65015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E4=BA=A8=E8=80=80?= <2640788668@qq.com> Date: Tue, 20 Dec 2022 23:37:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\344\270\216\344\275\234\344\270\232.md" | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 "21 \345\215\242\344\272\250\350\200\200/20221219 f\346\226\271\346\263\225\345\244\215\344\271\240\344\270\216\344\275\234\344\270\232.md" diff --git "a/21 \345\215\242\344\272\250\350\200\200/20221219 f\346\226\271\346\263\225\345\244\215\344\271\240\344\270\216\344\275\234\344\270\232.md" "b/21 \345\215\242\344\272\250\350\200\200/20221219 f\346\226\271\346\263\225\345\244\215\344\271\240\344\270\216\344\275\234\344\270\232.md" new file mode 100644 index 0000000..75e2348 --- /dev/null +++ "b/21 \345\215\242\344\272\250\350\200\200/20221219 f\346\226\271\346\263\225\345\244\215\344\271\240\344\270\216\344\275\234\344\270\232.md" @@ -0,0 +1,121 @@ +## 笔记 + +#### 方法重载 + +方法重载概念 + +方法重载指同一个类中定义的多个方法之间的关系,满足下列条件的多个方法相互构成重载 + +1.多个方法在同一个类中 + +2.多个方法具有相同的方法名 + +3.多个方法的参数不相同,类型不同或者数量不同 + +###### 注意: + +重载仅对应方法的定义,与方法的调用无关,调用方式参照标准格式 + +#### 方法传递 + +- 基本数据类型的参数,形式参数的改变,不影响实际参数。(每个方法在栈内存中,都会有独立的栈空间,方法运行结束后就会弹栈消失) +- 引用数据类型的传参,传入的是地址值,内存中会造成两个引用指向同一个内存的效果,所以 + +即使方法弹栈,堆内存中的数据也已经是改变后的结果(对于引用类型的参数,形式参数的改变,影响实际参数的值) + +## 作业 + +```java + 1. //用自定义函数实现求某数组元素的和(大小不固定) + public static void main(String[] args) { + sum(); + } + public static void sum(){ + int[] arr=new int[3]; + int sum=0; + System.out.println("请输入你要的数:"); + Scanner sc=new Scanner(System.in); + for (int i = 0; i < arr.length ; i++) { + arr[i]= sc.nextInt(); + sum+=arr[i]; + } + System.out.println("和为:"+sum); + } + + + 2. //计算圆的面积与周长 + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.print("请输入圆的半径:"); + double r = scanner.nextDouble(); + System.out.println(r); + yuan(r); + } + public static void yuan(double r) { + // 计算圆的面积和周长 + double mj = 3.14 * r * r; + double zc = 2 * 3.14 * r; + System.out.println(mj); + System.out.println(zc); + } + + +import java.util.Random; +import java.util.Scanner; + +public class D9 { + 3.//在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组, + // 并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) + public static void main(String[] args) { + System.out.println("请输入一个0-10的整数"); + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + if (n > 10 | n < 0) { + System.out.println("无效数字"); + } else { + shuzi(n); + } + + } + public static void shuzi ( int n) { + int d = 0; + Random ran = new Random(); + int[] num = new int[20]; + for (int i = 0; i < num.length; i++) { + num[i] = ran.nextInt(11); + System.out.print(num[i]+" "); + if (n == num[i]) { + d++; + } + } + System.out.print("您输入的数字" + n + "重复数" + d + "次"); + } + } + + +public class D10 { + 4. //用户输入整数n,计算1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) + public static void main(String[] args) { + System.out.println("请输入数字"); + Jc(); + } + public static void Jc(){ + Scanner sc=new Scanner(System.in); + int n= sc.nextInt(); + long sum=0;long num; + for (int i=1;i<=n;i++){ + num=1; + for (int j=1;j<=i;j++){ + num=num*j; + sum+=num; + } + } + System.out.println(sum); + } +} + + +5. //在主函数中接收10个数存入数组,在自定义函数中,将该数组中的最大值与第一个元素交换, + // 最小值与最后一个元素交换,然后在主函数中输出交换后的数组————————————这一题俺真的不会(╥﹏╥) +``` + -- Gitee