From 00489ed4066f5f88d26bcbca7ac9f1270a6f8e1d Mon Sep 17 00:00:00 2001 From: xiong-wenxin <2583569497@qq.com> Date: Tue, 5 Jan 2021 21:06:47 +0800 Subject: [PATCH] xwx --- .../Demo1.java" | 56 +++++++++++++++++ .../Demo2.java" | 21 +++++++ .../Demo3.java" | 25 ++++++++ .../Demo4.java" | 26 ++++++++ .../Demo5.java" | 26 ++++++++ .../Demo6.java" | 61 +++++++++++++++++++ 6 files changed, 215 insertions(+) create mode 100644 "Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo1.java" create mode 100644 "Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo2.java" create mode 100644 "Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo3.java" create mode 100644 "Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo4.java" create mode 100644 "Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo5.java" create mode 100644 "Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo6.java" diff --git "a/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo1.java" "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo1.java" new file mode 100644 index 0000000..ec042be --- /dev/null +++ "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo1.java" @@ -0,0 +1,56 @@ +package com.md.lesson9; + +import java.util.Scanner; + +import javax.swing.Spring; + +public class Demo1 { + + public static void main(String[] args) { + //计算器 + Scanner scanner=new Scanner(System.in); + System.out.println("请输入计算方法"); + char a=scanner.next().charAt(0); + System.out.println("请输入第一个数"); + int b=scanner.nextInt(); + System.out.println("请输入第二个数"); + int c=scanner.nextInt(); + switch (a) { + case '+': + System.out.println("两数之和是"+jia(b,c)); + break; + case '-': + System.out.println("两数之差是"+jian(b,c)); + break; + case '*': + System.out.println("两数之积是"+cheng(b,c)); + break; + case '/': + System.out.println("两数之商是"+chu(b,c)); + break; + case '%': + System.out.println("两数之余是"+yu(b,c)); + break; + default: + System.out.println("输入错误"); + break; + } + + } + public static int jia(int b,int c) { + return b+c; + } + public static int jian(int b,int c) { + return b-c; + } + public static int cheng(int b,int c) { + return b*c; + } + public static int chu(int b,int c) { + return b/c; + } + public static int yu(int b,int c) { + return b%c; + } +} + diff --git "a/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo2.java" "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo2.java" new file mode 100644 index 0000000..9a1f01a --- /dev/null +++ "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo2.java" @@ -0,0 +1,21 @@ +package com.md.lesson9; + + +public class Demo2{ + + public static void main(String[] args) { + // 运用方法比较数组中值的大小。 + int [] a= {66,77,88,99,22,33}; + aa(a); + System.out.println("最大的数是:"+aa(a)); + } + public static int aa(int[] a) { + int max=a[0]; + for (int i = 1; i < a.length; i++) { + if (a[i]>=max) { + max=a[i]; + } + } + return max; + } +} diff --git "a/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo3.java" "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo3.java" new file mode 100644 index 0000000..7359042 --- /dev/null +++ "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo3.java" @@ -0,0 +1,25 @@ +package com.md.lesson9; + +import java.util.Scanner; + +public class Demo3{ + + public static void main(String[] args) { + // 用户输入高,打印如下图形 +//* +//*** +//***** +//******* + Scanner scanner=new Scanner(System.in); + int a; + System.out.println("请输入高:"); + a=scanner.nextInt(); + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= 2*i-1; j++) { + System.out.print("*"); + } + System.out.println(); + } + } + +} diff --git "a/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo4.java" "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo4.java" new file mode 100644 index 0000000..c0cd33f --- /dev/null +++ "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo4.java" @@ -0,0 +1,26 @@ +package com.md.lesson9; + +import java.util.Scanner; + +public class Demo4 { + + public static void main(String[] args) { + // 用户输入高,打印如下图形 + //******* + //***** + //*** + //* + Scanner scanner=new Scanner(System.in); + int a; + System.out.println("请输入高:"); + a=scanner.nextInt(); + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= 2*(a-i)+1; j++) { + System.out.print("*"); + } + System.out.println(); + } + } + +} + diff --git "a/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo5.java" "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo5.java" new file mode 100644 index 0000000..88cc355 --- /dev/null +++ "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo5.java" @@ -0,0 +1,26 @@ +package com.md.lesson9; + +import java.util.Scanner; + +public class Demo5 { + + public static void main(String[] args) { + // 用户输入n,求结果: +// 1!+2!+3!...n! + Scanner scanner = new Scanner(System.in); + System.out.println("请输入累乘最后的数字:"); + int a=scanner.nextInt(); + int b=0; + int c=1; + int d=0; + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= i; j++) { + b=j; + } + c=b*c; + d=d+c; + } + System.out.println("累乘结果为:"+d); + } + +} diff --git "a/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo6.java" "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo6.java" new file mode 100644 index 0000000..b9b1ff1 --- /dev/null +++ "b/Java\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\206\212\346\226\207\351\221\253/Demo6.java" @@ -0,0 +1,61 @@ +package com.md.lesson9; + +import java.util.Scanner; + +public class Demo6 { + + public static void main(String[] args) { + // 编写四个函数,分别计算长方形、正方形、三角形、圆形的面积, +// 合理设置参数和返回值,main方法中根据用户的选择调用。 + Scanner scanner = new Scanner(System.in); + System.out.println("请输入计算图形"); + System.out.println("1.正方形"); + System.out.println("2.长方形"); + System.out.println("3.三角形"); + System.out.println("4.圆形"); + int a = scanner.nextInt(); + + switch (a) { + case 1: + System.out.println("请输入正方形边长"); + int b= scanner.nextInt(); + System.out.println("正方形面积是"+zheng(b)); + break; + case 2: + System.out.println("请输入长方形的长"); + int c= scanner.nextInt(); + System.out.println("请输入长方形的宽"); + int d= scanner.nextInt(); + System.out.println("长方形面积是"+chang(c,d)); + break; + case 3: + System.out.println("请输入三角形的高"); + int e= scanner.nextInt(); + System.out.println("请输入三角形的底边长"); + int f= scanner.nextInt(); + System.out.println("三角形面积是"+san(e,f)); + break; + case 4: + System.out.println("请输入圆形的半径"); + double g= scanner.nextDouble(); + System.out.println("圆形的面积是"+yuan(g)); + break; + + default: + break; + } + + } + public static int zheng(int b) { + return b*b; + } + public static int chang(int c,int d) { + return c*d; + } + public static int san(int e,int f) { + return e*f/2; + } + public static double yuan(double g) { + return 3.14*g*g; + } +} -- Gitee