From d32c9e233ef8ec35de4e1f634190924003499276 Mon Sep 17 00:00:00 2001 From: liu-siying-1 <13542745679@139.com> Date: Wed, 6 Jan 2021 07:57:55 +0800 Subject: [PATCH] first commit --- .../Demo02.java" | 21 +++++++++++++ .../Demo03.java" | 22 +++++++++++++ .../Demo04.java" | 31 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 "java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo02.java" create mode 100644 "java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo03.java" create mode 100644 "java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo04.java" diff --git "a/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo02.java" "b/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo02.java" new file mode 100644 index 0000000..2b2cd02 --- /dev/null +++ "b/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo02.java" @@ -0,0 +1,21 @@ +import java.util.Scanner; + +public class Demo02 { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + System.out.println("请输入X的值:"); + int x = scan.nextInt(); + System.out.println("请输入Y的值:"); + int y = scan.nextInt(); + System.out.println("请输入Z的值:"); + int z = scan.nextInt(); + x=x*x*x; + y=y*y*y; + z=z*z*z; + int sum = x+z+y; + System.out.println("S的结果是:"+sum); + + } + +} diff --git "a/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo03.java" "b/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo03.java" new file mode 100644 index 0000000..fd93eaa --- /dev/null +++ "b/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo03.java" @@ -0,0 +1,22 @@ + +public class Demo03 { + + public static void main(String[] args) { + Scanner scanner =new Scanner(System.in); + System.out.println("请输入n的值"); + int n=scanner.nextInt(); + System.out.println("请再输入m的值"); + int m=scanner.nextInt(); + System.out.println("最终结果为:"+num(n,m)); + + } + + public static int num(int n, int m) { + int sum=1; + for (int i = 1; i <=n; i++) { + sum*=m; + } + return sum; + } + +} diff --git "a/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo04.java" "b/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo04.java" new file mode 100644 index 0000000..799ca4a --- /dev/null +++ "b/java\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\345\210\230\346\200\235\347\233\210/Demo04.java" @@ -0,0 +1,31 @@ +import java.util.Random; +import java.util.Scanner; + +public class Demo04 { +//在主函数中产生20个0-10之间的随机数,将这20个随 + //机数存入数组,并通过函数计算某个数在这些随机数中出 + //现的次数(这“某个数”是在主函数中由用户输入的) + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + Random random = new Random(); + int[] numArray = new int [20]; + for (int i = 0; i < 20; i++) { + numArray[i]=random.nextInt(10)+1; + System.out.print("numArray["+i+"]="+numArray[i]+"\t"); + + } System.out.println(); + System.out.println("请输入0~10的一个数:"); + int a = scan.nextInt(); + int sum=0; + for (int i = 0; i < numArray.length; i++) { + if(a==numArray[i]) { + sum++; + } + + } + System.out.println(a+"在数组中的次数为:"+sum); + + } +} + + -- Gitee