From 385a84bccae4b0e8bcd78c61c7ac57197129730f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=9B=A8=E6=99=B4?= <2137161545@qq.com> Date: Mon, 19 Dec 2022 23:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20221211 \344\275\234\344\270\232.md" | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git "a/03 \345\276\220\351\233\250\346\231\264/20221211 \344\275\234\344\270\232.md" "b/03 \345\276\220\351\233\250\346\231\264/20221211 \344\275\234\344\270\232.md" index 99c6613..4c77c59 100644 --- "a/03 \345\276\220\351\233\250\346\231\264/20221211 \344\275\234\344\270\232.md" +++ "b/03 \345\276\220\351\233\250\346\231\264/20221211 \344\275\234\344\270\232.md" @@ -82,3 +82,153 @@ public class class4 { } ``` +5. **编写函数,计算圆的面积和周长,在主函数中接受圆的半径,在自定义函数中计算并输出** + +```java +import java.util.Scanner; + +public class class10 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("请输入圆的半径(cm):"); + double r=sc.nextDouble(); + System.out.println("当半径为"+r+"cm时,它的周长为"+getc(r)+"cm,面积为"+gets(r)+"cm²"); + } + static double getc(double r){ + return 2*3.14*r; + } + static double gets(double r){ + return 3.14*r*r; + } +} +``` + +6. **在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的)** + +```java +import java.util.Random; +import java.util.Scanner; + +public class class11 { + public static void main(String[] args) { + int[] num=new int[20]; + Random ran=new Random(); + int sum=0; + for (int n=0;n max) { + int n= num[0]; + num[0]=max; + max = n; + } + } + int min=num[0]; + for (int m:num){ + if (m