diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/copilot.data.migration.agent.xml b/.idea/copilot.data.migration.agent.xml new file mode 100644 index 0000000..4ea72a9 --- /dev/null +++ b/.idea/copilot.data.migration.agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/copilot.data.migration.ask.xml b/.idea/copilot.data.migration.ask.xml new file mode 100644 index 0000000..7ef04e2 --- /dev/null +++ b/.idea/copilot.data.migration.ask.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/copilot.data.migration.ask2agent.xml b/.idea/copilot.data.migration.ask2agent.xml new file mode 100644 index 0000000..1f2ea11 --- /dev/null +++ b/.idea/copilot.data.migration.ask2agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/copilot.data.migration.edit.xml b/.idea/copilot.data.migration.edit.xml new file mode 100644 index 0000000..8648f94 --- /dev/null +++ b/.idea/copilot.data.migration.edit.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5b52afa --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HelloWorld/Hello.java b/HelloWorld/Hello.java deleted file mode 100644 index c70617d..0000000 --- a/HelloWorld/Hello.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Hello { - public void greet(String name) { - System.out.println("Hello, " + name + "!"); - } -} diff --git a/HelloWorld/HelloWorld.class b/HelloWorld/HelloWorld.class deleted file mode 100644 index ec2ba65..0000000 Binary files a/HelloWorld/HelloWorld.class and /dev/null differ diff --git a/HelloWorld/HelloWorld.java b/HelloWorld/HelloWorld.java deleted file mode 100644 index cdbc291..0000000 --- a/HelloWorld/HelloWorld.java +++ /dev/null @@ -1,11 +0,0 @@ - - -public class HelloWorld { - public static void main(String[] args) { - System.out.println("Hello, World!"); - - Hello hello = new Hello(); - hello.greet("Alice"); - - } -} diff --git a/JavaBasicStudy/HelloJava.java b/JavaBasicStudy/HelloJava.java deleted file mode 100644 index 679d9d5..0000000 --- a/JavaBasicStudy/HelloJava.java +++ /dev/null @@ -1,27 +0,0 @@ -package JavaBasicStudy; - -public class HelloJava { - enum Color { - RED,ORANGE,YELLOW,GREEN,BLUE,BLACK,WHITE - } - - public static void main(String[] args) { - HelloJava helloJava = new HelloJava(); - helloJava.testHuHangTao(); - } - - - - public void testHuHangTao(){ - SWPUStudent HuHangTao = new SWPUStudent("胡航滔", 20, "2024520541", "网络工程", 3.8, "hht@stu.swpu.edu.cn", "12345678901", "四川省广安市", "男"); - HuHangTao.ShowInfo(); - - HuHangTao.setGpa(4.5); - HuHangTao.setEmail(HuHangTao.getStudentID() + "@stu.swpu.edu.cn"); - HuHangTao.setPhoneNumber("18782345678"); - HuHangTao.ShowInfo(); - } - -} - - diff --git a/JavaBasicStudy/JavaBasicDataType.java b/JavaBasicStudy/JavaBasicDataType.java deleted file mode 100644 index d4014fe..0000000 --- a/JavaBasicStudy/JavaBasicDataType.java +++ /dev/null @@ -1,25 +0,0 @@ -package JavaBasicStudy; - -public class JavaBasicDataType { - public int integerType = 100; //整数类型 - public float floatType = 3.14f; //单精度浮点类型 - public double doubleType = 3.141592653589793; //双精度浮点类型 - public char charType = 'A'; //字符类型 - public boolean booleanType = true; //布尔类型 - public String stringType = "Hello, Java!"; //字符串类型 - public long longType = 123456789L; //长整型 - public short shortType = 32000; //短整型 - public byte byteType = 100; //字节型 - - public void displayDataTypes() { - System.out.println("整数类型 (int): " + integerType); - System.out.println("单精度浮点类型 (float): " + floatType); - System.out.println("双精度浮点类型 (double): " + doubleType); - System.out.println("字符类型 (char): " + charType); - System.out.println("布尔类型 (boolean): " + booleanType); - System.out.println("字符串类型 (String): " + stringType); - System.out.println("长整型 (long): " + longType); - System.out.println("短整型 (short): " + shortType); - System.out.println("字节型 (byte): " + byteType); - } -} diff --git a/LICENSE b/LICENSE deleted file mode 100644 index f5ba692..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2025 ShuMengya - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b3ac81a --- /dev/null +++ b/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + smy.javastudy + SmyJavaStudy + 1.0-SNAPSHOT + + + 11 + 11 + UTF-8 + + + \ No newline at end of file diff --git a/src/main/java/smy/javastudy/GrammarPractice.java b/src/main/java/smy/javastudy/GrammarPractice.java new file mode 100644 index 0000000..4b19da5 --- /dev/null +++ b/src/main/java/smy/javastudy/GrammarPractice.java @@ -0,0 +1,17 @@ +package smy.javastudy; + +public class GrammarPractice { + public void Exchange(String input){ + switch (input){ + case "刘道熙": + System.out.println("是畜生"); + break; + case "唐伟": + System.out.println("是大帅比"); + break; + default: + System.out.println("不知道"); + break; + } + } +} diff --git a/src/main/java/smy/javastudy/JavaBasicDataType.java b/src/main/java/smy/javastudy/JavaBasicDataType.java new file mode 100644 index 0000000..56c040a --- /dev/null +++ b/src/main/java/smy/javastudy/JavaBasicDataType.java @@ -0,0 +1,74 @@ +package smy.javastudy; + +public class JavaBasicDataType { + public int integerType = 100; //整数类型 + public float floatType = 3.14f; //单精度浮点类型 + public double doubleType = 3.141592653589793; //双精度浮点类型 + public char charType = 'A'; //字符类型 + public boolean booleanType = true; //布尔类型 + public String stringType = "Hello, Java!"; //字符串类型 + public long longType = 123456789L; //长整型 + public short shortType = 32000; //短整型 + public byte byteType = 100; //字节型 + + public void displayDataTypes() { + System.out.println("=================================================="); + System.out.println("整数类型 (int): " + integerType); + System.out.println("单精度浮点类型 (float): " + floatType); + System.out.println("双精度浮点类型 (double): " + doubleType); + System.out.println("字符类型 (char): " + charType); + System.out.println("布尔类型 (boolean): " + booleanType); + System.out.println("字符串类型 (String): " + stringType); + System.out.println("长整型 (long): " + longType); + System.out.println("短整型 (short): " + shortType); + System.out.println("字节型 (byte): " + byteType); + System.out.println("=================================================="); + } + + public void ShowDataTypesInfo() { + System.out.println("=================================================="); + System.out.println("基本类型:byte 二进制位数:"+Byte.SIZE); + System.out.println("包装类:java.lang.Byte"); + System.out.println("最小值:Byte.MIN_VALUE="+Byte.MIN_VALUE); + System.out.println("最大值:Byte.MAX_VALUE="+Byte.MAX_VALUE); + System.out.println(); + + System.out.println("基本类型:short 二进制位数:"+Short.SIZE); + System.out.println("包装类:java.lang.Short"); + System.out.println("最小值:Short.MIN_VALUE="+Short.MIN_VALUE); + System.out.println("最大值:Short.Max_Value="+Short.MAX_VALUE); + System.out.println(); + + System.out.println("基本类型:int 二进制位数:"+Integer.SIZE); + System.out.println("包装类:java.lang.Integer"); + System.out.println("最小值:Integer.MIN_VALUE="+Integer.MIN_VALUE); + System.out.println("最大值:Integer.Max_Value="+Integer.MAX_VALUE); + System.out.println(); + + System.out.println("基本类型:long 二进制位数:"+Long.SIZE); + System.out.println("包装类:java.lang.Long"); + System.out.println("最小值:Long.MIN_VALUE="+Long.MIN_VALUE); + System.out.println("最大值:Long.Max_Value="+Long.MAX_VALUE); + System.out.println(); + + System.out.println("基本类型:float 二进制位数:"+Float.SIZE); + System.out.println("包装类:java.lang.Float"); + System.out.println("最小值:Float.MIN_VALUE="+Float.MIN_VALUE); + System.out.println("最大值:Float.Max_Value="+Float.MAX_VALUE); + System.out.println(); + + System.out.println("基本类型:double 二进制位数:"+Double.SIZE); + System.out.println("包装类:java.lang.Double"); + System.out.println("最小值:Double.MIN_VALUE="+Double.MIN_VALUE); + System.out.println("最大值:Double.Max_Value="+Double.MAX_VALUE); + System.out.println(); + + System.out.println("基本类型:char 二进制位数:"+Character.SIZE); + System.out.println("包装类:java.lang.Character"); + System.out.println("最小值:Character.MIN_VALUE="+(int)Character.MIN_VALUE); + System.out.println("最大值:Character.Max_Value="+(int)Character.MAX_VALUE); + + System.out.println("=================================================="); + + } +} diff --git a/src/main/java/smy/javastudy/Main.java b/src/main/java/smy/javastudy/Main.java new file mode 100644 index 0000000..0c6d5df --- /dev/null +++ b/src/main/java/smy/javastudy/Main.java @@ -0,0 +1,43 @@ +package smy.javastudy; + + + +public class Main { + final double PI = 3.14159; + int decimal = 100; + int octal = 0144; + int hexa = 0x64; + + //项目唯一主函数 + public static void main(String[] args) { + //TIP 当文本光标位于高亮显示的文本处时按 + // 查看 IntelliJ IDEA 建议如何修正。 + System.out.printf("Hello and welcome!\n"); + Main main = new Main(); + main.testHuHangTao(); + + JavaBasicDataType dataType = new JavaBasicDataType(); + dataType.ShowDataTypesInfo(); + + GrammarPractice grammarPractice = new GrammarPractice(); + grammarPractice.Exchange("刘道熙"); + grammarPractice.Exchange("唐伟"); + grammarPractice.Exchange("树萌芽"); + + NumberAndMathDemo demo = new NumberAndMathDemo(); + demo.numberClassUsage(); + demo.mathClassUsage(); + } + + public void testHuHangTao(){ + SWPUStudent HuHangTao = new SWPUStudent("胡航滔", 20, "2024520541", "网络工程", 3.8, "hht@stu.swpu.edu.cn", "12345678901", "四川省广安市", "男"); + HuHangTao.ShowInfo(); + + HuHangTao.setGpa(4.5); + HuHangTao.setEmail(HuHangTao.getStudentID() + "@stu.swpu.edu.cn"); + HuHangTao.setPhoneNumber("18782345678"); + HuHangTao.ShowInfo(); + + + } +} \ No newline at end of file diff --git a/src/main/java/smy/javastudy/NumberAndMathDemo.java b/src/main/java/smy/javastudy/NumberAndMathDemo.java new file mode 100644 index 0000000..fd4f4a1 --- /dev/null +++ b/src/main/java/smy/javastudy/NumberAndMathDemo.java @@ -0,0 +1,89 @@ +package smy.javastudy; + +import java.math.BigDecimal; +import java.math.BigInteger; + +public class NumberAndMathDemo { + + public void numberClassUsage() { + System.out.println("=========================Number类的用法========================="); + + // Number 是一个抽象类,其子类包括 Integer、Double、Float 等。 + // 我们可以用它来持有任何数字类型。 + Number num1 = 123; + Number num2 = 456.78; + + System.out.println("num1 是: " + num1 + ",类型是 " + num1.getClass().getName()); + System.out.println("num2 是: " + num2 + ",类型是 " + num2.getClass().getName()); + + // xxxValue() 方法用于转换为基本数据类型 + System.out.println("num1 作为 int: " + num1.intValue()); + System.out.println("num1 作为 double: " + num1.doubleValue()); + System.out.println("num2 作为 int: " + num2.intValue()); // 注意:这会截断小数部分 + System.out.println("num2 作为 long: " + num2.longValue()); + System.out.println("num2 作为 float: " + num2.floatValue()); + System.out.println("num2 作为 byte: " + num2.byteValue()); + System.out.println("num2 作为 short: " + num2.shortValue()); + + // compareTo() 方法 (来自 Comparable 接口, 由 Number 的子类实现) + Integer int1 = 100; + Integer int2 = 200; + System.out.println("比较 100 和 200: " + int1.compareTo(int2)); // 如果小于则为-1,如果等于则为0,如果大于则为1 + + // equals() 方法 + Double double1 = 123.45; + Double double2 = 123.45; + System.out.println("用 equals() 比较 123.45 和 123.45: " + double1.equals(double2)); + + // 使用 BigInteger 和 BigDecimal 处理非常大的数字 + BigInteger bigInt = new BigInteger("12345678901234567890"); + BigDecimal bigDecimal = new BigDecimal("1234567890.0987654321"); + System.out.println("BigInteger: " + bigInt); + System.out.println("BigDecimal: " + bigDecimal); + + // 大数的算术运算 + BigInteger bigIntSum = bigInt.add(new BigInteger("1")); + System.out.println("BigInteger 的和: " + bigIntSum); + BigDecimal bigDecimalProduct = bigDecimal.multiply(new BigDecimal("2.5")); + System.out.println("BigDecimal 的积: " + bigDecimalProduct); + System.out.println("=========================Number类的用法========================="); + } + + public void mathClassUsage() { + System.out.println("\n=========================Math类的用法========================="); + + double x = 45.6; + double y = -78.9; + double angle = 45.0; + + // 基本算术方法 + System.out.println(y + " 的绝对值是: " + Math.abs(y)); + System.out.println(x + " 的向上取整是: " + Math.ceil(x)); // 向上取整 + System.out.println(x + " 的向下取整是: " + Math.floor(x)); // 向下取整 + System.out.println(x + " 的四舍五入是: " + Math.round(x)); // 四舍五入到最近的整数 + System.out.println(x + " 和 " + y + " 的最大值是: " + Math.max(x, y)); + System.out.println(x + " 和 " + y + " 的最小值是: " + Math.min(x, y)); + + // 指数和对数函数 + System.out.println("e^2 是: " + Math.exp(2)); + System.out.println("10 的自然对数是: " + Math.log(10)); + System.out.println("100 的以10为底的对数是: " + Math.log10(100)); + System.out.println("2^3 是: " + Math.pow(2, 3)); + System.out.println("16 的平方根是: " + Math.sqrt(16)); + + // 三角函数 + double radians = Math.toRadians(angle); + System.out.println(angle + " 度的正弦值是: " + Math.sin(radians)); + System.out.println(angle + " 度的余弦值是: " + Math.cos(radians)); + System.out.println(angle + " 度的正切值是: " + Math.tan(radians)); + System.out.println("将 " + radians + " 弧度转换为度: " + Math.toDegrees(radians)); + + // 随机数生成 + // Math.random() 返回一个大于等于 0.0 且小于 1.0 的 double 值 + System.out.println("一个随机数: " + Math.random()); + // 获取一个范围内的随机整数,例如 [1, 10] + int randomInt = (int) (Math.random() * 10) + 1; + System.out.println("一个 1 到 10 之间的随机整数: " + randomInt); + System.out.println("\n=========================Math类的用法========================="); + } +} diff --git a/JavaBasicStudy/SWPUStudent.java b/src/main/java/smy/javastudy/SWPUStudent.java similarity index 93% rename from JavaBasicStudy/SWPUStudent.java rename to src/main/java/smy/javastudy/SWPUStudent.java index b2b805f..7e1f54b 100644 --- a/JavaBasicStudy/SWPUStudent.java +++ b/src/main/java/smy/javastudy/SWPUStudent.java @@ -1,4 +1,4 @@ -package JavaBasicStudy; +package smy.javastudy; public class SWPUStudent { private String name; //学生姓名 @@ -11,6 +11,7 @@ public class SWPUStudent { private String address; //住址 private String gender; //性别 + //学生类构造函数 public SWPUStudent(String name, int age, String studentID, String major, double gpa, String email, String phoneNumber, String address, String gender) { this.name = name; this.age = age; @@ -23,7 +24,7 @@ public class SWPUStudent { this.gender = gender; } - + //展示学生基本信息 public void ShowInfo() { System.out.println("=================================="); System.out.println("西南石油大学学生信息:"); @@ -42,6 +43,7 @@ public class SWPUStudent { //======================对学生属性进行封装================================== + //姓名 public String getName() { return name; } @@ -51,7 +53,7 @@ public class SWPUStudent { } - + //年龄 public int getAge() { return age; } @@ -61,7 +63,7 @@ public class SWPUStudent { } - + //学生ID public String getStudentID() { return studentID; } @@ -71,7 +73,7 @@ public class SWPUStudent { } - + //专业 public String getMajor() { return major; } @@ -81,7 +83,7 @@ public class SWPUStudent { } - + //学分绩点 public double getGpa() { return gpa; } @@ -91,7 +93,7 @@ public class SWPUStudent { } - + //邮箱 public String getEmail() { return email; } @@ -101,7 +103,7 @@ public class SWPUStudent { } - + //电话号码 public String getPhoneNumber() { return phoneNumber; } @@ -111,7 +113,7 @@ public class SWPUStudent { } - + //家庭住址 public String getAddress() { return address; } @@ -121,7 +123,7 @@ public class SWPUStudent { } - + //年龄 public String getGender() { return gender; } diff --git a/src/main/java/smy/javastudy/TestNumberClass.java b/src/main/java/smy/javastudy/TestNumberClass.java new file mode 100644 index 0000000..8f7ed66 --- /dev/null +++ b/src/main/java/smy/javastudy/TestNumberClass.java @@ -0,0 +1,27 @@ +package smy.javastudy; +import java.lang.Number; + +public class TestNumberClass { + + //基本类型转换 + public void typeConversion(){ + Number num1 = 1234.56; + System.out.println(num1); + System.out.println(num1.getClass()); + System.out.println(num1.intValue()); + System.out.println(num1.longValue()); + System.out.println(num1.doubleValue()); + System.out.println(num1.floatValue()); + System.out.println(num1.byteValue()); + } + + //数值比较 + public void compareNum(){ + Integer x = 10; + Double y = 10.0; + System.out.println(x.doubleValue()==y.doubleValue()); + } + + //处理大数 + //public +}