From 0c1b1b53dbdb7ce64c5e4aebb72d3ed237be8b13 Mon Sep 17 00:00:00 2001 From: polyhymnia <2281017491@qq.com> Date: Mon, 28 Dec 2020 15:11:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Java=E7=AC=AC=E4=BA=94=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../New.java" | 39 ++++++++++++++++++ .../Work1.java" | 40 +++++++++++++++++++ .../Work2.java" | 36 +++++++++++++++++ .../Work3.java" | 24 +++++++++++ 4 files changed, 139 insertions(+) create mode 100644 "Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/New.java" create mode 100644 "Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work1.java" create mode 100644 "Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work2.java" create mode 100644 "Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work3.java" diff --git "a/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/New.java" "b/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/New.java" new file mode 100644 index 0000000..fd77c47 --- /dev/null +++ "b/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/New.java" @@ -0,0 +1,39 @@ +package com.md.demo; + +import java.util.Scanner; + +public class New { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("请输入你要的一个字符"); + char ch = scanner.next().charAt(0); + + int i = (char)ch;//在unicode中的顺序编码 + /* + System.out.println('A'+0);//65 + System.out.println('Z'+0);//90 + System.out.println('a'+0);//97 + System.out.println('z'+0);//122 + */ + + if (i>=65&&i<=122) { + if (i>=65&&i<=90) { + System.out.println("你输入的字符是大写字母"); + } + if (i>=97&&i<=122) { + System.out.println("你输入的字符是小写字母"); + } + } + else { + System.out.println("你输入的字符不是字母"); + } + if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='e') { + System.out.println("你输入的字符是韵母"); + } + else { + System.out.println("你输入的字符不是韵母"); + } + + + } +} diff --git "a/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work1.java" "b/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work1.java" new file mode 100644 index 0000000..b789571 --- /dev/null +++ "b/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work1.java" @@ -0,0 +1,40 @@ +package com.md.Demo; + +import java.time.Year; +import java.util.Scanner; + +/* + * 某公司即将为员工买保险, 要求如下: + * 已婚的男、 女性都可以买保险, + * 未婚男性25岁以下不提供保险, 25岁以上(包括) 提供保险, + * 未婚女性22岁以下不提供保险, 22岁以上(包括) 提供保险, + * 请用程序实现以上功能,接受员工的信息, + * 显示公司是否为他提供保险 + * (已未婚用Y和N表示, 性别用男和女表示) + + * + * + * + */ +public class Work1{ + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("请输入性别"); + char sex = scanner.next().charAt(0); + + System.out.println("请输入是否已婚"); + String married = scanner.next(); + + System.out.println("请输入年龄"); + byte age = scanner.nextByte(); + + if (married == "Y" ) { + System.out.println("提供保险"); + } + else { + if ((sex == '男' && married.equals("N") & age>=25 )|| (sex=='女' && married.equals("N") & age>=22)) { + System.out.println("不提供保险"); + } + } + } +} diff --git "a/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work2.java" "b/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work2.java" new file mode 100644 index 0000000..416c07f --- /dev/null +++ "b/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work2.java" @@ -0,0 +1,36 @@ +package com.md.Demo; + +import java.util.Scanner; + +public class Work2 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("请输入a"); + int a = scanner.nextInt(); + System.out.println("请输入b"); + int b = scanner.nextInt(); + System.out.println("请输入c"); + int c = scanner.nextInt(); + + if (a > b | a > c) { + if(b>c) { + System.out.println("顺序为"+(a) +(b) + (c)); + } + else { + System.out.println("顺序为"+(a) +(c) + (b)); + } + } + + else if (a > b | a < c) { + System.out.println("顺序为"+(c) +(a) +(b)); + } + else if (a < b | a < c) { + if (b > c) { + System.out.println("顺序为"+(b) +(c) +(a)); + } + else { + System.out.println("顺序为"+(b) +(a) +(c)); + } + } + } +} diff --git "a/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work3.java" "b/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work3.java" new file mode 100644 index 0000000..bc7fecb --- /dev/null +++ "b/Java\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Work3.java" @@ -0,0 +1,24 @@ +package com.md.Demo; + +import java.util.Scanner; + +public class Work3 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("请输入一个数"); + int a = scanner.nextInt(); + System.out.println("请输入一个数"); + int b = scanner.nextInt(); + if (ab) { + System.out.println("最大值"+(a)); + }else { + System.out.println("最大值"+(b)); + } + } +} -- Gitee From fd893cc0373b31a7f9fea5825eb6ab166e367048 Mon Sep 17 00:00:00 2001 From: polyhymnia <2281017491@qq0com> Date: Wed, 30 Dec 2020 19:59:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Java=E7=AC=AC=E5=85=AD=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Demo1.java" | 42 +++++++++++++++++++ .../For1.java" | 29 +++++++++++++ .../While1.java" | 12 ++++++ .../While2.java" | 12 ++++++ .../While3.java" | 31 ++++++++++++++ .../While4.java" | 18 ++++++++ 6 files changed, 144 insertions(+) create mode 100644 "Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Demo1.java" create mode 100644 "Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/For1.java" create mode 100644 "Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While1.java" create mode 100644 "Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While2.java" create mode 100644 "Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While3.java" create mode 100644 "Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While4.java" diff --git "a/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Demo1.java" "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Demo1.java" new file mode 100644 index 0000000..e7c0c4b --- /dev/null +++ "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/Demo1.java" @@ -0,0 +1,42 @@ +package com.md.Dome; + + +import java.util.Scanner; + +public class Demo1//食谱 + { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + System.out.println("请输入今天周几"); + String ch = scan.next(); + + switch (ch) { + case "周一": + System.out.println("今天吃鸡蛋"); + break; + case "周二": + System.out.println("今天吃鱼 "); + break; + case "周三": + System.out.println("今天吃青菜"); + break; + case "周四": + System.out.println("今天吃牛肉"); + break; + case "周五": + System.out.println("今天吃虾"); + break; + case "周六": + System.out.println("今天吃汉堡"); + break; + case "周日": + System.out.println("今天吃鸡翅"); + break; + default: + System.out.println("今天吃nml"); + break; + } + } + } + diff --git "a/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/For1.java" "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/For1.java" new file mode 100644 index 0000000..3533a13 --- /dev/null +++ "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/For1.java" @@ -0,0 +1,29 @@ +package com.md.Dome; + +import java.util.Scanner; + +public class For1 { + //用户输入一个数字n,判断是否为素数(只能被1和自身整除的数) + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("请输入一个>1的数"); + int num = scanner.nextInt(); + + for (int i = 2; i < num; i++) { + if (num==2) { + System.out.println(num + "是素数"); + break; + } + if (num>2) { + if (num%2==0) { + System.out.println(num + "不是素数"); + break; + } else { + System.out.println(num + "是素数"); + break; + } + + } + } + } +} diff --git "a/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While1.java" "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While1.java" new file mode 100644 index 0000000..7e6de59 --- /dev/null +++ "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While1.java" @@ -0,0 +1,12 @@ +package com.md.Dome; + +public class While1 { + public static void main(String[] args) { +// 使用循环语句在屏幕上打出一行*号(共10个),样子为:********** + int a = 1; + while (a<=10) { + System.out.println("*"); + a++; + } + } +} diff --git "a/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While2.java" "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While2.java" new file mode 100644 index 0000000..e116bd2 --- /dev/null +++ "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While2.java" @@ -0,0 +1,12 @@ +package com.md.Dome; + +public class While2 { +// 打印九九乘法表的一行:3*3=?、3*4=?、3*5=?、3*6=?、3*7=?、3*8=?、3*9=? + public static void main(String[] args) { + int b = 3 ; + while (b<=9) { + System.out.println(3 + "*" + b + " = "+(3*b)); + b++; + } + } +} diff --git "a/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While3.java" "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While3.java" new file mode 100644 index 0000000..752f505 --- /dev/null +++ "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While3.java" @@ -0,0 +1,31 @@ +package com.md.Dome; + +import java.util.Scanner; +//求和 +public class While3 { + public static void main(String[] args) { +/* + * + * 用循环的方法接受用户输入的五个成绩,若用户输入的成绩不在0~100之间, + * 则打印“该成绩有误,不列入计算”。 + * 在循环结束后求出所有输入正确的成绩的总和。 + */ + Scanner scan = new Scanner(System.in); + + int a = 1; + int b; + int sum = 0; + + while (a<6) { + System.out.println("请输入"+(a)+"的值"); + b = scan.nextInt(); + if(b>100||b<0) { + b = 0; + System.out.println("该成绩有误,不列入计算"); + } + sum += b; + a++; + } + System.out.println("总和"+sum); + } +} diff --git "a/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While4.java" "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While4.java" new file mode 100644 index 0000000..b99d5cd --- /dev/null +++ "b/Java\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/While4.java" @@ -0,0 +1,18 @@ +package com.md.Dome; + +import java.util.Scanner; + +public class While4 { +//将1998-2008年之间的闰年年份输出。 + public static void main(String[] args) { + // Scanner scanner = new Scanner(System.in); + System.out.println("输出1998-2020的闰年"); + for (int i = 1998; i < 2021; i++) { + if (i%4==0|| i%400==0) { + System.out.println(i+"是闰年"); + } else { + System.out.println(i+"不是闰年"); + } + } + } +} -- Gitee