From ecd61d38e9e3b791ed92cb544f38206764d98dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=BE=99=E8=85=BE?= <2235304668@qq.com> Date: Tue, 20 Dec 2022 00:16:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E7=AC=AC=E5=8D=81=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022.12.20\345\217\202\346\225\260.md" | 175 ++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 "22 \345\274\240\351\276\231\350\205\276/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/2022.12.20\345\217\202\346\225\260.md" diff --git "a/22 \345\274\240\351\276\231\350\205\276/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/2022.12.20\345\217\202\346\225\260.md" "b/22 \345\274\240\351\276\231\350\205\276/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/2022.12.20\345\217\202\346\225\260.md" new file mode 100644 index 0000000..3458f81 --- /dev/null +++ "b/22 \345\274\240\351\276\231\350\205\276/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/2022.12.20\345\217\202\346\225\260.md" @@ -0,0 +1,175 @@ +# 作业 + +## ① + +```java +import java.util.Scanner; +//编写函数,计算圆的面积和周长,在主函数中接受圆的半径,在自定义函数中计算并输出 +public class Guteacher1 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("请输入圆的半径:"); + double r=sc.nextDouble(); + gainmianji(r); + gainzhouchang(r); + + } + + public static void gainmianji(double r) { + double mianji = r * r; + System.out.println("这个圆的面积为:" + mianji + "π"); + } + + public static void gainzhouchang(double r){ + double zhouchang=2*r; + System.out.println("这个圆的周长为:"+zhouchang+"π"); + } +} +``` + +## ② + +```java +import java.util.Random; +import java.util.Scanner; +//在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) +public class Guteacher2 { + public static void main(String[] args) { + System.out.println("请输入一个0到10之间的随机数:"); + Scanner sc = new Scanner(System.in); + int num=sc.nextInt(); +// 20个0-10之间的随机数,20个数 + int[] bb=new int[20]; + for (int i=0;i aa[i]) { + xiao = aa[i]; + xiao2 = i; + } + } +// 换位 + da = aa[aa.length - 1]; + aa[aa.length - 1] = xiao; + aa[max2] = da; + +// 打印 + for (int o = 0; o < aa.length; o++) { + System.out.println(aa[o]); + } + } +} +``` + + + +# 笔记 + +##### 随机数的范围 + +int xxx=ran.nextInt(数字) + +##### 方法的定义 + +ps:写在main外面 + +public static void 方法名(){ + +方法体; + +} + +参数(int... a=1....) \ No newline at end of file -- Gitee