From 6216fc55a2665e2d0df59777e96d3f0893129cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E7=8E=B2?= <1516489926@qq.com> Date: Wed, 21 Dec 2022 00:51:04 +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 --- ...60\347\273\204\350\277\220\347\224\250.md" | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 "29 \350\267\257\347\216\262/20221221 \346\226\271\346\263\225\344\270\255\346\225\260\347\273\204\350\277\220\347\224\250.md" diff --git "a/29 \350\267\257\347\216\262/20221221 \346\226\271\346\263\225\344\270\255\346\225\260\347\273\204\350\277\220\347\224\250.md" "b/29 \350\267\257\347\216\262/20221221 \346\226\271\346\263\225\344\270\255\346\225\260\347\273\204\350\277\220\347\224\250.md" new file mode 100644 index 0000000..2e1770a --- /dev/null +++ "b/29 \350\267\257\347\216\262/20221221 \346\226\271\346\263\225\344\270\255\346\225\260\347\273\204\350\277\220\347\224\250.md" @@ -0,0 +1,155 @@ +### 作业 + +Arrays.toString()打印 + +continue;跳过 + +1.编写函数,计算圆的面积和周长,在主函数中接受圆的半径,在自定义函数中计算并输出 + +```java + +import java.util.Scanner; + +public class ON11 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入圆的半径"); + int a = sc.nextInt(); + double b =area(a); + System.out.println("圆的面积是:"+b); + double c = perimeter(a); + System.out.println("圆的周长是:"+c); + + } + public static double area(int a){ + double w =3.14*a; + return w; + } + public static double perimeter(int a){ + double p =3.14*a*a; + return p ; + } +} +``` + +2.在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) + +```java +import java.util.Random; +import java.util.Scanner; + +public class ON12 { + public static void main(String[] args){ + int[] a = new int[20]; + for (int n = 0; n < 20; n++) { + Random ran = new Random(); + a[n] = ran.nextInt(10); + } + + Scanner sc = new Scanner(System.in); + System.out.println("请输入数字(1-10):"); + int b = sc.nextInt(); + sum(a,b);} + public static void sum(int[] a,int b){ + int count = 0; + for (int i = 0;i arr[k]) { + min = arr[0]; + } + } + int max = arr[0]; + for (int i = 1; i < arr.length; i++) { + if (max < arr[i]) { + max = arr[9]; + } + } + arr[0]=max; + arr[9]=min; + System.out.print("["); + for (int p = 0; p < arr.length; p++) { + System.out.print(arr[p]); + if (p==arr.length-1){ + continue; + } + System.out.print("."); + } + System.out.print("]"); + } +} +``` + +4.用自定义函数是实现求某数组元素的和(大小不固定) + +```java +import java.util.Scanner; + +public class ON14 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入数组的长度(一定要是整数):"); + int[] arr = new int[sc.nextInt()]; + for (int k =0; k