diff --git "a/13 \345\274\240\345\276\267\345\272\267/20221216 \346\226\271\346\263\225.md" "b/13 \345\274\240\345\276\267\345\272\267/20221216 \346\226\271\346\263\225.md" index acec7ced253eb33542e7ecb998f7b34c58c58998..c6941102d07662d0be97ff5a55377ba88163fcb9 100644 --- "a/13 \345\274\240\345\276\267\345\272\267/20221216 \346\226\271\346\263\225.md" +++ "b/13 \345\274\240\345\276\267\345\272\267/20221216 \346\226\271\346\263\225.md" @@ -1,4 +1,166 @@ -## 作业一 +## 作业 + +编写函数,计算圆的面积和周长,在主函数中接受圆的半径,在自定义函数中计算并输出 + +``` +import java.util.Scanner; + +public class A2 { + public static void main(String[] args) { + Scanner vc = new Scanner(System.in); + System.out.println("输入圆的半径:"); + double b = vc.nextDouble(); + change(b); + } + + public static void change(double b){ + double S = b*b; + System.out.println("圆的面积:"+ S ); + double A = 2*b; + System.out.println("圆的周长:"+A); + } + +} +``` + + + +## 作业 + + 在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) + +``` +public class A1 { + public static void main(String[] args) { + Random ss = new Random(); + int[] sz = new int[20]; + System.out.println("随机二十个数:"); + for (int i=0;i< sz.length;i++){ + sz[i]= ss.nextInt(); + } + for (int z=0;z< sz.length;z++){ + System.out.println(sz[z]); + } + Scanner cs=new Scanner(System.in); + System.out.println(); + System.out.println("输入数字:"); + int zz = cs.nextInt(); + System.out.println(zz+"在数组出现了"+shu(zz,sz)); + } + public static int shu(int zz,int[] sz){ + int q = 0; + for (int e =0;e< sz.length;e ++){ + if (zz == sz[e]){ + q ++; + } + + } + return q; + } +``` + + + +## 作业 + + 在主函数中接收10个数存入数组,在自定义函数中,将该数组中的最大值与第一个元素交换,最小值与最后一个元素交换,然后在主函数中输出交换后的数组 + +``` + +``` + + + +## 作业 + +用自定义函数是实现求某数组元素的和(大小不固定) + +``` + public static void main(String[] args) { + Random r = new Random(); + int arr[] = new int[5]; + for (int i = 0 ; i < arr.length ; i ++) { + arr[i] = ran.nextInt(90)+10; + } + System.out.print("随机数组为:"); + for (int i = 0 ; i < arr.length ; i ++) { + System.out.print(arr[i] + " "); + } + System.out.println(); + System.out.println("和为:" + number(arr)); + } + public static int number(int arr[]){ + int num = 0; + for (int i = 0 ; i < arr.length ; i++) { + num += arr[i]; + } + return num; +``` + + + +## 作业 + + 用户输入整数n,计算1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) + +``` +import java.util.Scanner; +public class A4 { + public static void main(String[] args) { + Scanner cs = new Scanner(System.in); + System.out.println("请输入n的值:"); + double num = cs.nextInt(); + System.out.println("1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!)=" + number(num)); + } + public static double number(double num) { + double he = 0; + for (int a = 1 ; a <= num ; a ++) { + for (int j = 1 ; j <= a ; j ++) { + he += j; + } + } + return he; + } +} +``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +## 作业 ```java import java.util.Scanner; @@ -22,7 +184,7 @@ public class A2 { -## 作业二 +## 作业 ``` import java.util.Scanner;