diff --git a/实验5/.vscode/settings.json b/实验5/.vscode/settings.json new file mode 100755 index 0000000..0ac215c --- /dev/null +++ b/实验5/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/实验5/README.md b/实验5/README.md new file mode 100755 index 0000000..a43b9f6 --- /dev/null +++ b/实验5/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/实验5/src/task1/Main.java b/实验5/src/task1/Main.java new file mode 100755 index 0000000..240a424 --- /dev/null +++ b/实验5/src/task1/Main.java @@ -0,0 +1,25 @@ +//Main.java +package task1; + +import java.util.Date; +import java.util.Scanner; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Locale; + +public class Main { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + SimpleDateFormat in = new SimpleDateFormat("yyyy M dd"); + Date d = new Date(); + try { + d = in.parse(input.nextLine()); + } catch (ParseException e) { + e.printStackTrace(); + } + SimpleDateFormat out = new SimpleDateFormat("yyyy MMMM dd EEEE", Locale.ENGLISH); + String formattedDate = out.format(d); + System.out.println("今天是" + out.format(d).toUpperCase()); + + } +} \ No newline at end of file diff --git a/实验5/src/task2/Main.java b/实验5/src/task2/Main.java new file mode 100755 index 0000000..743bc70 --- /dev/null +++ b/实验5/src/task2/Main.java @@ -0,0 +1,27 @@ +//Main.java +package task2; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + Date inDate = new Date(); + SimpleDateFormat inFormat = new SimpleDateFormat("yyyy年M月d日", Locale.CHINA); + System.out.print("请输入您家孩子的出生日期(格式为yyyy年M月d日):"); + try { + inDate = inFormat.parse(input.nextLine()); + } catch (ParseException e) { + e.printStackTrace(); + } + long inTimeStamp = inDate.getTime(); + long outTimeStamp = inTimeStamp + (long) 100 * 24 * 60 * 60 * 1000; + Date outDate = new Date(outTimeStamp); + SimpleDateFormat outFormat = new SimpleDateFormat("yyyy年M月dd日 EEEE", Locale.CHINA); + System.out.println("经计算,您家孩子的百日宴应该设在" + outFormat.format(outDate)); + } +} diff --git a/实验5/src/task3/StringLearning.java b/实验5/src/task3/StringLearning.java new file mode 100755 index 0000000..565ff61 --- /dev/null +++ b/实验5/src/task3/StringLearning.java @@ -0,0 +1,22 @@ +package task3; + +import java.util.Scanner; + +public class StringLearning { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + String stringExample = scanner.next(); + String endStr = " end"; + // ---------------------Begin------------------------ + System.out.println(stringExample);// 1.输出原字符串 + System.out.println(stringExample.length());// 2.求出字符串长度 + // 3.字符串转换成相应的大/小写 + System.out.println(stringExample.toUpperCase()); + System.out.println(stringExample.toLowerCase()); + // 4.截取指定位置的字符串(3-7) + System.out.println(stringExample.substring(3, 7)); + // 5.字符串相加具体输出要求请看测试说明。 + System.out.println(stringExample + endStr); + // ---------------------End------------------------ + } +} diff --git a/实验5/src/task4/Main.java b/实验5/src/task4/Main.java new file mode 100755 index 0000000..b620d19 --- /dev/null +++ b/实验5/src/task4/Main.java @@ -0,0 +1,15 @@ +//Main.java +package task4; + +import java.lang.Math; + +public class Main { + public static void main(String[] args) { + double value1 = 2, value2 = 0; + System.out.println("绝对值:\t" + Math.abs(value1)); + System.out.println("3次幂:\t" + Math.pow(value1, 3)); + System.out.println("二次方根:\t" + Math.pow(value1, 0.5)); + System.out.println("sin值:\t" + Math.sin(value1)); + System.out.println("较大者:\t" + Math.max(value1, value2)); + } +} diff --git a/实验5/src/task5/Roster.java b/实验5/src/task5/Roster.java new file mode 100755 index 0000000..3035249 --- /dev/null +++ b/实验5/src/task5/Roster.java @@ -0,0 +1,18 @@ +package task5; + +import java.util.Scanner; + +public class Roster { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + /********** Begin *********/ + String roster1 = "张三,李四,王五"; + String roster2 = scanner.nextLine(); + if (roster1.equals(roster2)) { + System.out.println("相同"); + } else { + System.out.println("不同"); + } + /********** End *********/ + } +}