From 4c82676efc95af51a2f08fd60cc2c8f0a697da39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E4=BA=A8=E4=BC=9F?= <529310475@qq.com> Date: Wed, 21 Dec 2022 00:37:02 +0800 Subject: [PATCH] =?UTF-8?q?21=E5=8F=B7=E7=9A=84=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20221221\344\275\234\344\270\232.md" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "11 \351\202\271\344\272\250\344\274\237/20221221\344\275\234\344\270\232.md" diff --git "a/11 \351\202\271\344\272\250\344\274\237/20221221\344\275\234\344\270\232.md" "b/11 \351\202\271\344\272\250\344\274\237/20221221\344\275\234\344\270\232.md" new file mode 100644 index 0000000..46d0433 --- /dev/null +++ "b/11 \351\202\271\344\272\250\344\274\237/20221221\344\275\234\344\270\232.md" @@ -0,0 +1,59 @@ +# 作业 + +编写函数,计算圆的面积和周长,在主函数中接受圆的半径,在自定义函数中计算并输出 + +```java +import java.util.Scanner; + +public class J1 { + public static void main(String[] args) { + Scanner Sc = new Scanner(System.in); + System.out.println("输入圆的半径"); + int a= Sc.nextInt(); + double r = 3.14; + mianji(a,r); + zouchang(a,r); + } + public static void mianji(int a,double r){ + System.out.println(r*a*a); + } + public static void zouchang(int a,double r){ + System.out.println(r*a*2); + } +} +``` + +在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) + +```java +import java.util.Random; +import java.util.Scanner; + +public class J2 { + public static void main(String[] args) { + long[] a = new long[20]; + for (int i = 0; i < 20;i++){ + Random random=new Random(); + int b =random.nextInt(10)+11; + System.out.println(a+""); + Scanner Sc = new Scanner(System.in); + System.out.println("请输入某个数"); + long x =Sc.nextLong(); + cisum(a,x); + } + } + public static void cisum(long[] a,long x){ + int count =0; + for (int i=0; i