From 06f401a7a3f631ed7c6398fd888d96e54d799217 Mon Sep 17 00:00:00 2001 From: pp20020501 <2382571669@qq.com> Date: Mon, 4 Jan 2021 23:24:48 +0800 Subject: [PATCH] java --- .../Demo1shixin.java" | 22 +++++++++++++ .../Demo2kongxin.java" | 26 +++++++++++++++ .../Demo3chitaozi.java" | 19 +++++++++++ .../Demo4fengshu.java" | 33 +++++++++++++++++++ .../Demo5lingxing.java" | 31 +++++++++++++++++ .../Demo6shuixianhuashu.java" | 29 ++++++++++++++++ .../Demo7chengfakojue.java" | 25 ++++++++++++++ .../Demo8yuangong.java" | 22 +++++++++++++ 8 files changed, 207 insertions(+) create mode 100644 "Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo1shixin.java" create mode 100644 "Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo2kongxin.java" create mode 100644 "Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo3chitaozi.java" create mode 100644 "Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo4fengshu.java" create mode 100644 "Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo5lingxing.java" create mode 100644 "Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo6shuixianhuashu.java" create mode 100644 "Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo7chengfakojue.java" create mode 100644 "Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo8yuangong.java" diff --git "a/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo1shixin.java" "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo1shixin.java" new file mode 100644 index 0000000..35705e4 --- /dev/null +++ "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo1shixin.java" @@ -0,0 +1,22 @@ +package com.pjt.Demo; + +import java.util.Scanner; + +public class Demo1shixin { +/* + * 用户输入正方形边长,用*打印出实心正方形。 + */ + public static void main(String[] args){ + Scanner scanner=new Scanner(System.in); + System.out.println("请输入正方形边长:"); + int a=scanner.nextInt(); + + for (int i = 1; i <=a; i++) { + for (int j = 1; j<=a; j++) { + System.out.print(" *"); + } + System.out.println(); + } + + } +} \ No newline at end of file diff --git "a/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo2kongxin.java" "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo2kongxin.java" new file mode 100644 index 0000000..b356361 --- /dev/null +++ "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo2kongxin.java" @@ -0,0 +1,26 @@ +package com.pjt.Demo; + +import java.util.Scanner; + +public class Demo2kongxin { +/* + * 用户输入正方形边长,用*打印出空心正方形。 + */ + public static void main(String[] args) { + Scanner scanner=new Scanner(System.in); + System.out.println("请输入正方形边长:"); + int a=scanner.nextInt(); + + for (int i = 0; i 100) { + System.out.println("成绩输入有误!"); + continue; + } + if (a==0) { + break; + } + sum=sum+a; + num++; + } + System.out.println("sun="+sum); + System.out.println("平均数="+sum/num); + } +} diff --git "a/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo5lingxing.java" "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo5lingxing.java" new file mode 100644 index 0000000..dd734ea --- /dev/null +++ "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo5lingxing.java" @@ -0,0 +1,31 @@ +package com.pjt.Demo; + +import java.util.Iterator; + +import com.sun.tools.classfile.Synthetic_attribute; + +public class Demo5lingxing { +/* + * 菱形 + */ + public static void main(String[] args) { + for (int i = 1; i <=4; i++) { + for (int j = 1; j <=4-i; j++) { + System.out.print(" "); + } + for (int j = 1; j <=2*i-1; j++) { + System.out.print("*"); + } + System.out.println(); + } + for (int i =3; i>=1; i--) { + for (int j = 1; j <=4-i; j++) { + System.out.print(" "); + } + for (int j = 1; j <=2*i-1; j++) { + System.out.print("*"); + } + System.out.println(); + } + } +} diff --git "a/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo6shuixianhuashu.java" "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo6shuixianhuashu.java" new file mode 100644 index 0000000..492f5d5 --- /dev/null +++ "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo6shuixianhuashu.java" @@ -0,0 +1,29 @@ +package com.pjt.Demo; + +import java.nio.Buffer; +import java.util.Iterator; +import java.util.Scanner; + +public class Demo6shuixianhuashu { +/* + * 需求:在控制台输出所有的“水仙花数” +解释:什么是水仙花数? + 水仙花数,指的是一个三位数,个位、十位、百位的数字立方和等于原数 + 例如: 153 1*1*1 + 5*5*5 + 3*3*3 = 153 + */ + public static void main(String[] args) { + int gewei=0; + int shiwei=0; + int baiwei=0; + Scanner scanner=new Scanner(System.in); + for (int i = 100; i <1000; i++) { + gewei=i%10; + shiwei=(i/10)%10; + baiwei=i/100; + if (i == gewei*gewei*gewei+shiwei*shiwei*shiwei+baiwei*baiwei*baiwei) { + System.out.println(i+""); + } + } + + } +} diff --git "a/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo7chengfakojue.java" "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo7chengfakojue.java" new file mode 100644 index 0000000..5d37498 --- /dev/null +++ "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo7chengfakojue.java" @@ -0,0 +1,25 @@ +package com.pjt.Demo; + +import javax.sound.midi.SysexMessage; + +public class Demo7chengfakojue { + /* + 1 * 1 = 1 + 2 * 1 = 2 2 * 2 = 4 + 3 * 1 = 3 3 * 2 = 6 3 * 3 = 9 + 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 + 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 + 6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36 + 7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49 + 8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64 + 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 + */ + public static void main(String[] args) { + for (int i = 1; i <10; i++) { + for (int j = 1; j<=i; j++) + System.out.print(j+"*"+i+"="+(j*i)+" "); + System.out.println(); + } + } + } + diff --git "a/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo8yuangong.java" "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo8yuangong.java" new file mode 100644 index 0000000..77bb993 --- /dev/null +++ "b/Java\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\346\275\230\346\231\266\345\251\267/Demo8yuangong.java" @@ -0,0 +1,22 @@ +package com.pjt.Demo; + +import java.util.Scanner; + +public class Demo8yuangong { +/* + * 开发部有5名员工, 编写一个程序, 用于接收每个员工的年龄 + * , 计算并输出开发部员工的平均年龄, 最大年龄及最小年龄。 + */ + public static void main(String[] args) { + int[] age; + age = new int[4]; + int max,min; + int sum=0; + Scanner scan =new Scanner (System.in); + for (int i = 0; i < 60; i++) { + System.out.println("输入年龄:"); + age[i]=scan.nextInt(); + } + } + } + -- Gitee