From 1391698149b312ac79ebc982474b86b34c1376b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B0=B8=E6=B7=B3?= <2678158018@qq.com> Date: Tue, 20 Dec 2022 18:30:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AC=AC=E5=8D=81=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 --- ...14\346\254\241\346\226\271\346\263\225.md" | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 "18 \345\276\220\346\260\270\346\267\263/20221219 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" diff --git "a/18 \345\276\220\346\260\270\346\267\263/20221219 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" "b/18 \345\276\220\346\260\270\346\267\263/20221219 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" new file mode 100644 index 0000000..7c25b05 --- /dev/null +++ "b/18 \345\276\220\346\260\270\346\267\263/20221219 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" @@ -0,0 +1,144 @@ +作业 + +编写函数,计算圆的面积和周长,在主函数中接受圆的半径,在自定义函数中计算并输出 + +```java +import java.util.Scanner; + +public class gu { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("输入⚪的半径"); + ad(sc.nextDouble(),3.14); + } + public static void ad(double a, double b){ + System.out.println("半径是"+2*b*a); + System.out.println("面积是"+b*a*a); + } + +} +``` + + 在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) + +```java +import java.util.Arrays; +import java.util.Scanner; + +public class shuzu { + public static void main(String[] args) { + long[] num = new long[10]; + for (int i = 0; i < 20; i++) { + num[i] = Math.round(Math.random() * 10); + } + Scanner sc = new Scanner(System.in); + System.out.println("输入一个数"); + long A = sc.nextLong(); + af(num, A); + } + + public static void af(long[] num, long A) { + int count = 0; + for (int i=0;i< num.length;i++){ + if (A==num[i]){ + count++; + } + } + System.out.println(Arrays.toString(num)); + System.out.println("次数是"+count); + } +} +``` + +在主函数中接收10个数存入数组,在自定义函数中,将该数组中的最大值与第一个元素交换,最小值与最后一个元素交换,然后在主函数中输出交换后的数组 + +```java +import java.util.Arrays; + +public class dfas { + public static void main(String[] args) { + int ac[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + System.out.println(Arrays.toString(ac)); + add(ac); + + } + + public static void add(int brr[]) { + int max = brr[0]; + int x = brr[0]; + + for (int i = 0; i < brr.length; i++) { + if (brr[i] > max) { + max = brr[i]; + } + } + for (int i=0;i< brr.length;i++){ + if (brr[i]==max){ + brr[i]=x; + } + } + brr[0]=max; + System.out.print("["); + for (int i=0;i< brr.length;i++){ + + System.out.print(brr[i]); + if (i== brr.length-1){ + continue; + } + System.out.print("、"); + } + System.out.print("]"); + } +} +``` + + 用自定义函数是实现求某数组元素的和(大小不固定) + +```java +import java.util.Scanner; + +public class rtyu { + public static void main(String[] args) { + System.out.println("输入数组元素个数"); + Scanner sd=new Scanner(System.in); + int[] ad=new int[sd.nextInt()]; + System.out.println("输入"+ad.length+"个数字"); + for (int i=0;i Date: Tue, 20 Dec 2022 18:31:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=AC=AC=E5=8D=81=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 --- ...47\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "18 \345\276\220\346\260\270\346\267\263/20221219 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" => "18 \345\276\220\346\260\270\346\267\263/20221220 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" (100%) diff --git "a/18 \345\276\220\346\260\270\346\267\263/20221219 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" "b/18 \345\276\220\346\260\270\346\267\263/20221220 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" similarity index 100% rename from "18 \345\276\220\346\260\270\346\267\263/20221219 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" rename to "18 \345\276\220\346\260\270\346\267\263/20221220 java\347\254\254\344\272\214\346\254\241\346\226\271\346\263\225.md" -- Gitee