diff --git a/ForDemo1.java b/ForDemo1.java new file mode 100644 index 000000000..da881ebb3 --- /dev/null +++ b/ForDemo1.java @@ -0,0 +1,35 @@ +public class ForDemo1 { + public static void main(String[] args) { + System.out.println("----3次Hello World----"); + for (int i = 0; i < 3; i++) { + if (i == 1) { + break; // 当i等于1时,跳出循环 + } + System.out.println("Hello World"); + } + + System.out.println("----4次Hello MySQL----"); + for (int i = 1; i < 5; i++) { + if (i == 3) { + continue; // 当i等于3时,跳过当前迭代 + } + System.out.println("Hello MySQL"); + } + + System.out.println("----5次Hello Spring----"); + for (int i = 1; i <= 5; i++) { + if (i == 3) { + continue; // 当i等于3时,跳过当前迭代 + } + System.out.println("Hello Spring"); + } + + System.out.println("----3次Hello Redis----"); + for (int i = 1; i <= 5; i += 2) { + if (i == 3) { + break; // 当i等于3时,跳出循环 + } + System.out.println("Hello Redis"); + } + } +} diff --git a/ForDemo2.java b/ForDemo2.java new file mode 100644 index 000000000..254408732 --- /dev/null +++ b/ForDemo2.java @@ -0,0 +1,21 @@ +public class ForDemo2 { + public static void main(String[] args){ + int [] numbers = {10, 20, 30, 40, 50}; + for(int x : numbers ){ + if (x == 30) { + break; // 当x等于30时,跳出循环 + } + System.out.print( x ); + System.out.print(","); + } + System.out.println(); + String [] names ={"James", "Larry", "Tom", "Lacy"}; + for( String name : names ) { + if (name.equals("Tom")) { + continue; // 当name等于"Tom"时,跳过当前循环,继续下一个循环 + } + System.out.print( name ); + System.out.print(","); + } + } +} diff --git a/ForDemo3.java b/ForDemo3.java new file mode 100644 index 000000000..bf452b6aa --- /dev/null +++ b/ForDemo3.java @@ -0,0 +1,21 @@ +public class ForDemo3 { + public static void main(String[] args) { + // 使用break + System.out.println("----使用break----"); + for (int i = 1; i <= 5; i++) { + if (i == 3) { + break; + } + System.out.println("Hello Break"); + } + + // 使用continue + System.out.println("----使用continue----"); + for (int i = 1; i <= 5; i++) { + if (i == 3) { + continue; + } + System.out.println("Hello Continue"); + } + } +} diff --git a/IfDemo1.java b/IfDemo1.java new file mode 100644 index 000000000..b9776de43 --- /dev/null +++ b/IfDemo1.java @@ -0,0 +1,18 @@ +public class IfDemo1 { + public static void main(String[] args) { + // 格式3: if(条件表达式){ 代码... } else if(条件表达式){ 代码... } ... else{ 代码... } + int score = 95; + // 绩效:0-60 C,60-80 B,80-90 A,90-100 A+ + if (score >= 0 && score < 60) { + System.out.println("分数是:" + score + ",绩效是:C"); + } else if (score >= 60 && score < 80) { + System.out.println("分数是:" + score + ",绩效是:B"); + } else if (score >= 80 && score < 90) { + System.out.println("分数是:" + score + ",绩效是:A"); + } else if (score >= 90 && score <= 100) { + System.out.println("分数是:" + score + ",绩效是:A+"); + } else { + System.out.println("录入的分数有毛病!"); + } + } +} \ No newline at end of file diff --git a/IfDemo2.java b/IfDemo2.java new file mode 100644 index 000000000..0080f8f70 --- /dev/null +++ b/IfDemo2.java @@ -0,0 +1,16 @@ +public class IfDemo2 { + public static void main(String[] args) { + // 嵌套的 if…else 语句 + int x = 30; + int y = 10; + if (x == 30) { + if (y == 20) { + System.out.print("X = 30 and Y = 20"); + } else { + System.out.println("X = 30 and Y != 20"); + } + } else { + System.out.println("X != 30"); + } + } +} diff --git a/Student.java b/Student.java new file mode 100644 index 000000000..5c1a9fc18 --- /dev/null +++ b/Student.java @@ -0,0 +1,38 @@ +public class Student { + // 1.局部变量:在方法、构造函数或块内部声明的变量。 + public void run() { + String weight = "100斤"; // 局部变量weight,必须有初始值。 + // 因为实例变量age没赋值,所以默认是0 + System.out.println(name + "现在" + age + "岁"); // 小明现在0岁 + System.out.println(name + weight + ",跑得很快"); // 小明100斤,跑得很快 + } + + // 2.实例变量:在类中声明,但在方法、构造函数或块之外。 + public String name = "小明"; // 公有实例变量name对子类可见 + private int age; // 私有实例变量age,仅在该类可见,不赋值,默认是0 + + // main方法,程序入口 + public static void main(String[] args) { + Student.onLineNumber++; // 22 + System.out.println(onLineNumber); + Student student = new Student(); + student.run(); + student.eat("方便面"); + student.study(); + } + + // 3.类变量:在类中用 static 关键字声明的变量,它们属于类而不是实例。 + public static int onLineNumber = 21; + private String major = "计算机科学"; + + // 4.参数变量:是方法或构造函数声明中的变量 + public void eat(String food) { // 参数变量food + System.out.println(name + "喜欢吃" + food); // 小明喜欢吃方便面 + } + + // 自定义方法 + public void study() { + System.out.println(name + "正在学习" + major); + } +} + diff --git a/da.java b/da.java new file mode 100644 index 000000000..dec1539b3 --- /dev/null +++ b/da.java @@ -0,0 +1,12 @@ +public class da { + public static void main(String[] args) { + int n = 7; + if (n >= 0 && n < 10) { + for (int i = 0; i < n; i++) { + System.out.println("He" + n + n +"o" + " Wor" + n + "d"); + } + } else { + System.out.println("n>10"); + } + } +} diff --git a/das/.keep b/das/.keep new file mode 100644 index 000000000..0940aef0b --- /dev/null +++ b/das/.keep @@ -0,0 +1,13 @@ +public class da { + public static void main(String[] args) { + int n = 7; + if (n >= 0 && n < 10) { + for (int i = 0; i < n; i++) { + System.out.println("He" + n + n +"o" + " Wor" + n + "d"); + } + } else { + System.out.println("n>10"); + } + } +} + diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml index a69d8feb2..f116196a2 100644 --- a/ruoyi-admin/src/main/resources/application-druid.yml +++ b/ruoyi-admin/src/main/resources/application-druid.yml @@ -8,7 +8,7 @@ spring: master: url: jdbc:mysql://localhost:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root - password: password + password: root # 从库数据源 slave: # 从数据源开关/默认关闭 diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index ffb65e8bd..eba813cf8 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -16,7 +16,7 @@ ruoyi: # 开发环境配置 server: # 服务器的HTTP端口,默认为80 - port: 80 + port: 5555 servlet: # 应用的访问路径 context-path: / diff --git a/ruoyi-system/src/main/ArrayToList.java b/ruoyi-system/src/main/ArrayToList.java new file mode 100644 index 000000000..f831ffa3e --- /dev/null +++ b/ruoyi-system/src/main/ArrayToList.java @@ -0,0 +1,10 @@ +import java.util.Arrays; +import java.util.List; + +public class ArrayToList { + public static void main(String[] args) { + String[] array = {"A", "B", "C", "D"}; + List list = Arrays.asList(array); + System.out.println("列表内容: " + list); + } +} diff --git a/ruoyi-system/src/main/ForDemo1.java b/ruoyi-system/src/main/ForDemo1.java new file mode 100644 index 000000000..bb45b0533 --- /dev/null +++ b/ruoyi-system/src/main/ForDemo1.java @@ -0,0 +1,35 @@ +public class ForDemo1 { + public static void main(String[] args) { + System.out.println("----3次Hello World----"); + for (int i = 0; i < 3; i++) { + if (i == 1) { + break; // 当i等于1时,跳出循环 + } + System.out.println("Hello World"); + } + + System.out.println("----4次Hello MySQL----"); + for (int i = 1; i < 5; i++) { + if (i == 3) { + continue; // 当i等于3时,跳过当前迭代 + } + System.out.println("Hello MySQL"); + } + + System.out.println("----5次Hello Spring----"); + for (int i = 1; i <= 5; i++) { + if (i == 3) { + continue; // 当i等于3时,跳过当前迭代 + } + System.out.println("Hello Spring"); + } + + System.out.println("----3次Hello Redis----"); + for (int i = 1; i <= 5; i += 2) { + if (i == 3) { + break; // 当i等于3时,跳出循环 + } + System.out.println("Hello Redis"); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/ForDemo2.java b/ruoyi-system/src/main/ForDemo2.java new file mode 100644 index 000000000..6753ab558 --- /dev/null +++ b/ruoyi-system/src/main/ForDemo2.java @@ -0,0 +1,21 @@ +public class ForDemo2 { + public static void main(String[] args){ + int [] numbers = {10, 20, 30, 40, 50}; + for(int x : numbers ){ + if (x == 30) { + break; // 当x等于30时,跳出循环 + } + System.out.print( x ); + System.out.print(","); + } + System.out.println(); + String [] names ={"James", "Larry", "Tom", "Lacy"}; + for( String name : names ) { + if (name.equals("Tom")) { + continue; // 当name等于"Tom"时,跳过当前循环,继续下一个循环 + } + System.out.print( name ); + System.out.print(","); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/ListToArray.java b/ruoyi-system/src/main/ListToArray.java new file mode 100644 index 000000000..f98b85dc6 --- /dev/null +++ b/ruoyi-system/src/main/ListToArray.java @@ -0,0 +1,13 @@ +import java.util.ArrayList; +import java.util.List; +public class ListToArray { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("A"); + list.add("B"); + list.add("C"); + // 列表转为数组 + String[] array = list.toArray(new String[0]); + System.out.println("数组内容: " + list.toString()); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/NewStuding.java b/ruoyi-system/src/main/NewStuding.java new file mode 100644 index 000000000..31226450f --- /dev/null +++ b/ruoyi-system/src/main/NewStuding.java @@ -0,0 +1,38 @@ +public class NewStudent { + /** + * 学生 + */ + private String name; + /** + * 名字 + */ + private String age;//定义 + + /** + * 年龄 + * @param inputName + * @param inputAge + */ + public NewStudent(String inputName,String inputAge){ + this.name = inputName; + this.age = inputAge; + } + public void eat(){ + System.out.println("吃饭"); + } + + /** + * 吃饭 + * @param food + */ + + public void eat(String food){ + System.out.println("学生吃的"+food); + } + public String eat(String food,String time){ + System.out.println("学生在" + time + "吃的" + food); + return"吃饱了";//定义吃饭的方法 + } +} + + diff --git a/ruoyi-system/src/main/Student.java b/ruoyi-system/src/main/Student.java new file mode 100644 index 000000000..a0eb77e37 --- /dev/null +++ b/ruoyi-system/src/main/Student.java @@ -0,0 +1,37 @@ +public class Student { + // 1.局部变量:在方法、构造函数或块内部声明的变量。 + public void run() { + String weight = "100斤"; // 局部变量weight,必须有初始值。 + // 因为实例变量age没赋值,所以默认是0 + System.out.println(name + "现在" + age + "岁"); // 小明现在0岁 + System.out.println(name + weight + ",跑得很快"); // 小明100斤,跑得很快 + } + + // 2.实例变量:在类中声明,但在方法、构造函数或块之外。 + public String name = "小明"; // 公有实例变量name对子类可见 + private int age; // 私有实例变量age,仅在该类可见,不赋值,默认是0 + + // main方法,程序入口 + public static void main(String[] args) { + Student.onLineNumber++; // 22 + System.out.println(onLineNumber); + Student student = new Student(); + student.run(); + student.eat("方便面"); + student.study(); + } + + // 3.类变量:在类中用 static 关键字声明的变量,它们属于类而不是实例。 + public static int onLineNumber = 21; + private String major = "计算机科学"; + + // 4.参数变量:是方法或构造函数声明中的变量 + public void eat(String food) { // 参数变量food + System.out.println(name + "喜欢吃" + food); // 小明喜欢吃方便面 + } + + // 自定义方法 + public void study() { + System.out.println(name + "正在学习" + major); + } +} diff --git a/ruoyi-system/src/main/Studing.java b/ruoyi-system/src/main/Studing.java new file mode 100644 index 000000000..9ff152281 --- /dev/null +++ b/ruoyi-system/src/main/Studing.java @@ -0,0 +1,4 @@ +public class NewStudent { + private String name; + private int age; +} diff --git a/ruoyi-system/src/main/TestArray.java b/ruoyi-system/src/main/TestArray.java new file mode 100644 index 000000000..3165e6e2f --- /dev/null +++ b/ruoyi-system/src/main/TestArray.java @@ -0,0 +1,37 @@ +public class TestArray { + /** + * + * @param args + */ + public static void main(String[] args) { + // double类型的数组 + double[] scores = new double[]{99.5, 88.0, 75.5}; + double[] scores1 = {99.5, 88.0, 75.5}; // 简化写法 + + // int类型的数组 + int[] ages = new int[]{12, 24, 36}; + int[] ages1 = {12, 24, 36}; // 简化写法 + + int size = 5; // 设置数组大小是10 + String[] names = new String[size]; // 定义数组 + names[0] = "孙悟空"; + names[1] = "贝吉塔"; + names[2] = "弗利萨"; + names[3] = "沙鲁"; + names[4] = "魔人布欧"; + // 编译不报错,运行报错,因为数组大小是5,这是数组里第6个元素,数组越界ArrayIndexOutOfBoundsException + // names[5] = "布尔玛"; + // 数组索引从 0 开始,所以索引值从 0 到 arrayRefVar.length-1 + for (int i = 0; i < names.length; i++) { + System.out.print("索引:" + i + names[i] + " "); + } + + System.out.println(); + + // 数组变量名存储的是数组在内存种的地址,数组是引用类型 + // [ 指的是 数组 + // D 指的是 数据类型double + // @ 指的是 在哪里 + System.out.println(scores); // [D@776ec8df,指的是数组的十六进制地址 + } +} diff --git a/ruoyi-system/src/main/TestStudent.java b/ruoyi-system/src/main/TestStudent.java new file mode 100644 index 000000000..eb38f80a4 --- /dev/null +++ b/ruoyi-system/src/main/TestStudent.java @@ -0,0 +1,9 @@ +public class TestStudent { + public static void main(String[] args){ + NewStudent student = new NewStudent("czh","19"); + student.eat(); + student.eat("sda"); + student.eat("sda"); + + } +} diff --git a/ruoyi-system/src/main/da.java b/ruoyi-system/src/main/da.java new file mode 100644 index 000000000..80ae53852 --- /dev/null +++ b/ruoyi-system/src/main/da.java @@ -0,0 +1,12 @@ +public class da { + public static void main(String[] args) { + int n = 7; + if (n >= 0 && n < 10) { + for (int i = 0; i < n; i++) { + System.out.println("He" + n + n +"o" + " Wor" + n + "d"); + } + } else { + System.out.println("n>10"); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/dd.java b/ruoyi-system/src/main/dd.java new file mode 100644 index 000000000..5ba87214f --- /dev/null +++ b/ruoyi-system/src/main/dd.java @@ -0,0 +1,11 @@ +public class ss { + public static void main(String[] args) { + String studentId = "20233011082"; + char lastDigit1 = studentId.charAt(studentId.length() - 2); + char lastDigit2 = studentId.charAt(studentId.length() - 1); + char[] lastTwoDigits = {lastDigit1, lastDigit2}; + for (char c : lastTwoDigits) { + System.out.print(c + " "); + } + } +} diff --git a/ruoyi-system/src/main/java.java b/ruoyi-system/src/main/java.java new file mode 100644 index 000000000..30d7f261c --- /dev/null +++ b/ruoyi-system/src/main/java.java @@ -0,0 +1,39 @@ + + +/** + * 定义一个累 + */ +public class Java { + /** + * 三个与类名相关的属性 + */ + private String name1; + private String name2; + + + + /** + * @param name + * @param name2 + */ + public Java(String name, String name2) { + this.name1 = name1; + this.name2 = name2; + + } + + + + /** + * main函数创建对象并调用两个方法 + */ + + public void java() { + System.out.println(name1 + "cc"); + } + public void sha() { + System.out.println(name2 + "xx"); + } +} + + diff --git a/ruoyi-system/src/main/java/ACoach.java b/ruoyi-system/src/main/java/ACoach.java new file mode 100644 index 000000000..9749267f3 --- /dev/null +++ b/ruoyi-system/src/main/java/ACoach.java @@ -0,0 +1,9 @@ +/** + * A级教练实现 + */ +public class ACoach implements Coach{ + @Override + public void command(){ + System.out.println("我是A级证书教练"); + } +} diff --git a/ruoyi-system/src/main/java/ACoachFactory.java b/ruoyi-system/src/main/java/ACoachFactory.java new file mode 100644 index 000000000..8d0e5dc62 --- /dev/null +++ b/ruoyi-system/src/main/java/ACoachFactory.java @@ -0,0 +1,9 @@ +/** + * A级教练工厂实现 + */ +public class ACoachFactory implements CoachFactory { + @Override + public Coach createCoach() { + return new ACoach(); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/ArrayToList.java b/ruoyi-system/src/main/java/ArrayToList.java new file mode 100644 index 000000000..321ba902a --- /dev/null +++ b/ruoyi-system/src/main/java/ArrayToList.java @@ -0,0 +1,22 @@ +import java.util.Arrays; +import java.util.List; + +/** + * ArrayToList + */ +public class ArrayToList { + /** + * main方法 + * @param args + */ + public static void main(String[] args) { + String[] array = {"A", "B", "C", "D"}; + /** + * 数组转为数列 + */ + List list = Arrays.asList(array); + System.out.println("列表内容: " + list); + } +} + + diff --git a/ruoyi-system/src/main/java/Book.java b/ruoyi-system/src/main/java/Book.java new file mode 100644 index 000000000..7977940f9 --- /dev/null +++ b/ruoyi-system/src/main/java/Book.java @@ -0,0 +1,6 @@ +/** + * 定义一个表示书本类型的接口 + */ +public interface Book { + String name(); +} diff --git a/ruoyi-system/src/main/java/BookInterface.java b/ruoyi-system/src/main/java/BookInterface.java new file mode 100644 index 000000000..587901f88 --- /dev/null +++ b/ruoyi-system/src/main/java/BookInterface.java @@ -0,0 +1,9 @@ +/** + * 定义一个表示书本类型的接口 + */ +public interface BookInterface { + String BookName(); + String BookAuthor(); + String BookISBN(); + void setBookInfo(String name, String author, String isbn); +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/Booking.java b/ruoyi-system/src/main/java/Booking.java new file mode 100644 index 000000000..e30c2fc3e --- /dev/null +++ b/ruoyi-system/src/main/java/Booking.java @@ -0,0 +1,25 @@ +public class Booking { + public static void main(String[] args) { + // 创建图书对象 + Books books = new Books(); + + // 设置图书信息 + books.setBookInfo("安德的游戏", "安德", "978-7-111-60453-3"); + + // 获取并打印图书名称 + System.out.println("名称: " + books.BookName()); + + // 获取并打印图书作者 + System.out.println("作者: " + books.BookAuthor()); + + // 获取并打印图书ISBN + System.out.println("ISBN: " + books.BookISBN()); + + // 使用多态形式调用图书信息类的方法 + BookInterface bookInterface = new Books(); + bookInterface.setBookInfo("中华上下五千年", "袁堂欣", "978-0-13-468599-1"); + System.out.println("名称: " + bookInterface.BookName()); + System.out.println("作者: " + bookInterface.BookAuthor()); + System.out.println("ISBN: " + bookInterface.BookISBN()); + } +} diff --git a/ruoyi-system/src/main/java/Books.java b/ruoyi-system/src/main/java/Books.java new file mode 100644 index 000000000..b94ffcf0f --- /dev/null +++ b/ruoyi-system/src/main/java/Books.java @@ -0,0 +1,27 @@ +public class Books implements BookInterface { + private String name; + private String author; + private String isbn; + + @Override + public String BookName() { + return name; + } + + @Override + public String BookAuthor() { + return author; + } + + @Override + public String BookISBN() { + return isbn; + } + + @Override + public void setBookInfo(String name, String author, String isbn) { + this.name = name; + this.author = author; + this.isbn = isbn; + } +} diff --git a/ruoyi-system/src/main/java/CCoach.java b/ruoyi-system/src/main/java/CCoach.java new file mode 100644 index 000000000..0f2d83044 --- /dev/null +++ b/ruoyi-system/src/main/java/CCoach.java @@ -0,0 +1,9 @@ +/** + * C级教练实现 + */ +public class CCoach implements Coach{ + @Override + public void command() { + System.out.println("我是C级证书教练"); + } +} diff --git a/ruoyi-system/src/main/java/CCoachFactory.java b/ruoyi-system/src/main/java/CCoachFactory.java new file mode 100644 index 000000000..04a16a51e --- /dev/null +++ b/ruoyi-system/src/main/java/CCoachFactory.java @@ -0,0 +1,9 @@ +/** + * C级教练工厂实现 + */ +public class CCoachFactory implements CoachFactory{ + @Override + public Coach createCoach() { + return new CCoach(); + } +} diff --git a/ruoyi-system/src/main/java/Circle.java b/ruoyi-system/src/main/java/Circle.java new file mode 100644 index 000000000..9cd73551b --- /dev/null +++ b/ruoyi-system/src/main/java/Circle.java @@ -0,0 +1,9 @@ +/** + * 实现Shape接口的圆类 + */ +public class Circle implements Shape { + @Override + public String name() { + return "圆"; + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/Coach.java b/ruoyi-system/src/main/java/Coach.java new file mode 100644 index 000000000..c428222c7 --- /dev/null +++ b/ruoyi-system/src/main/java/Coach.java @@ -0,0 +1,6 @@ +/** + * 教练接口 + */ +public interface Coach { + void command(); +} diff --git a/ruoyi-system/src/main/java/CoachFactory.java b/ruoyi-system/src/main/java/CoachFactory.java new file mode 100644 index 000000000..73aef82a1 --- /dev/null +++ b/ruoyi-system/src/main/java/CoachFactory.java @@ -0,0 +1,6 @@ +/** + * 教练工厂接口 + */ +public interface CoachFactory { + Coach createCoach(); +} diff --git a/ruoyi-system/src/main/java/Demo.java b/ruoyi-system/src/main/java/Demo.java new file mode 100644 index 000000000..50cc603a7 --- /dev/null +++ b/ruoyi-system/src/main/java/Demo.java @@ -0,0 +1,12 @@ +/** + * 演示程序 + */ +public class Demo { + public static void create(CoachFactory factory) { + factory.createCoach().command(); + } + public static void main(String[] args) { + create(new ACoachFactory()); + create(new CCoachFactory()); + } +} diff --git a/ruoyi-system/src/main/java/ForDemo1.java b/ruoyi-system/src/main/java/ForDemo1.java new file mode 100644 index 000000000..b2a6ee9a1 --- /dev/null +++ b/ruoyi-system/src/main/java/ForDemo1.java @@ -0,0 +1,55 @@ +public class ForDemo1 { + public static void main(String[] args) { + System.out.println("----3次Hello World----"); + for (int i = 0; i < 3; i++) { + if (i == 1) { + + /** + *当1等于3时,跳出当前循环 + */ + + break; + + } + System.out.println("Hello World"); + } + + System.out.println("----4次Hello MySQL----"); + for (int i = 1; i < 5; i++) { + if (i == 3) { + + /** + *当1等于3时,跳出当前循环 + */ + + continue; + } + System.out.println("Hello MySQL"); + } + + System.out.println("----5次Hello Spring----"); + for (int i = 1; i <= 5; i++) { + if (i == 3) { + + /** + *当i等于3时,跳过当前迭代 + */ + + continue; + } + System.out.println("Hello Spring"); + } + + System.out.println("----3次Hello Redis----"); + for (int i = 1; i <= 5; i += 2) { + if (i == 3) { + /** + *当i等于3时,跳过当前迭代 + */ + + break; + } + System.out.println("Hello Redis"); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/ForDemo2.java b/ruoyi-system/src/main/java/ForDemo2.java new file mode 100644 index 000000000..b7a67af99 --- /dev/null +++ b/ruoyi-system/src/main/java/ForDemo2.java @@ -0,0 +1,31 @@ +public class ForDemo2 { + public static void main(String[] args){ + int [] numbers = {10, 20, 30, 40, 50}; + for(int x : numbers ){ + if (x == 30) { + + /** + *当x等于30时,跳出循环 + */ + + break; + } + System.out.print( x ); + System.out.print(","); + } + System.out.println(); + String [] names ={"James", "Larry", "Tom", "Lacy"}; + for( String name : names ) { + if (name.equals("Tom")) { + + /** + *当name等于"Tom"时,跳过当前循环,继续下一个循环 + */ + + continue; + } + System.out.print( name ); + System.out.print(","); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/ForDemo3.java b/ruoyi-system/src/main/java/ForDemo3.java new file mode 100644 index 000000000..f2c648e49 --- /dev/null +++ b/ruoyi-system/src/main/java/ForDemo3.java @@ -0,0 +1,28 @@ +public class ForDemo3 { + public static void main(String[] args) { + + /** + * 使用break + */ + + System.out.println("----使用break----"); + for (int i = 1; i <= 5; i++) { + if (i == 3) { + break; + } + System.out.println("Hello Break"); + } + + /** + * 使用continue + */ + + System.out.println("----使用continue----"); + for (int i = 1; i <= 5; i++) { + if (i == 3) { + continue; + } + System.out.println("Hello Continue"); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/History.java b/ruoyi-system/src/main/java/History.java new file mode 100644 index 000000000..8c7b2a6d9 --- /dev/null +++ b/ruoyi-system/src/main/java/History.java @@ -0,0 +1,10 @@ +/** + * 实现Book接口的历史类 + */ +public class History implements Book { + @Override + public String name() { + return "历史"; + } + +} diff --git a/ruoyi-system/src/main/java/IfDemo1.java b/ruoyi-system/src/main/java/IfDemo1.java new file mode 100644 index 000000000..a9b7d0fca --- /dev/null +++ b/ruoyi-system/src/main/java/IfDemo1.java @@ -0,0 +1,18 @@ +public class IfDemo1 { + public static void main(String[] args) { + // 格式3: if(条件表达式){ 代码... } else if(条件表达式){ 代码... } ... else{ 代码... } + int score = 95; + // 绩效:0-60 C,60-80 B,80-90 A,90-100 A+ + if (score >= 0 && score < 60) { + System.out.println("分数是:" + score + ",绩效是:C"); + } else if (score >= 60 && score < 80) { + System.out.println("分数是:" + score + ",绩效是:B"); + } else if (score >= 80 && score < 90) { + System.out.println("分数是:" + score + ",绩效是:A"); + } else if (score >= 90 && score <= 100) { + System.out.println("分数是:" + score + ",绩效是:A+"); + } else { + System.out.println("录入的分数有毛病!"); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/IfDemo2.java b/ruoyi-system/src/main/java/IfDemo2.java new file mode 100644 index 000000000..d03ca3a34 --- /dev/null +++ b/ruoyi-system/src/main/java/IfDemo2.java @@ -0,0 +1,16 @@ +public class IfDemo2 { + public static void main(String[] args) { + // 嵌套的 if…else 语句 + int x = 30; + int y = 10; + if (x == 30) { + if (y == 20) { + System.out.print("X = 30 and Y = 20"); + } else { + System.out.println("X = 30 and Y != 20"); + } + } else { + System.out.println("X != 30"); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/Java.java b/ruoyi-system/src/main/java/Java.java new file mode 100644 index 000000000..fe931a4ed --- /dev/null +++ b/ruoyi-system/src/main/java/Java.java @@ -0,0 +1,38 @@ +package test.java; + +/** + * 定义一个累 + */ + +public class Java { + + /** + * 三个与类名相关的属性 + */ + + private String name1; + private String name2; + + /** + * @param name + * @param name2 + */ + + + public Java(String name, String name2) { + this.name1 = name1; + this.name2 = name2; + + } + + /** + * main函数创建对象并调用两个方法 + */ + + public void java() { + System.out.println(name1 + "cc"); + } + public void sha() { + System.out.println(name2 + "xx"); + } +} diff --git a/ruoyi-system/src/main/java/ListToArray.java b/ruoyi-system/src/main/java/ListToArray.java new file mode 100644 index 000000000..f613c1949 --- /dev/null +++ b/ruoyi-system/src/main/java/ListToArray.java @@ -0,0 +1,23 @@ +import java.util.ArrayList; +import java.util.List; +/** + * ListToArray + */ +public class ListToArray { + /** + * + * @param args + */ + public static void main(String[] args) { + + List list = new ArrayList<>(); + list.add("A"); + list.add("B"); + list.add("C"); + /** + * 数组转为数列 + */ + String[] array = list.toArray(new String[0]); + System.out.println("数组内容: " + list.toString()); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/Literature.java b/ruoyi-system/src/main/java/Literature.java new file mode 100644 index 000000000..5880a670d --- /dev/null +++ b/ruoyi-system/src/main/java/Literature.java @@ -0,0 +1,10 @@ +/** + * 实现Book接口的文学类 + */ +public class Literature implements Book { + @Override + public String name() { + return "文学"; + } + +} diff --git a/ruoyi-system/src/main/java/New.java b/ruoyi-system/src/main/java/New.java new file mode 100644 index 000000000..0a9ffdc30 --- /dev/null +++ b/ruoyi-system/src/main/java/New.java @@ -0,0 +1,30 @@ +//字符与字符串查找 +public class New{ + public static void main(String args[]){ + String str = "How qi bocome handsome like qi ge"; //定义一个长字符串 + System.out.println("该字符串为:"+str); + /***1、indexOf()方法查找字符首个出现位置格式1,2***/ + int index1 = str.indexOf(" "); //找到第一个空格所在的索引 + int index2 = str.indexOf(" ",4); //找到索引4以后的第一个空格所在索引 + System.out.println("第一个空格所在索引为:"+index1); + System.out.println("索引4以后的第一个空格所在索引为:"+index2); + System.out.println("*****************"); + /***2、lastIndexOf()方法查找字符最后出现位置格式1,2***/ + int index3 = str.lastIndexOf(" "); //找到最后一个空格所在的索引 + int index4 = str.lastIndexOf(" ",10);//找到索引10以后的第一个空格所在索引 + System.out.println("最后一个空格所在索引为:"+index3); + System.out.println("索引10以前最后一个空格所在索引为:"+index4); + System.out.println("*****************"); + /***3、indexOf()方法查找子字符串第一次出现位置格式1,2***/ + int index5 = str.indexOf("qi"); //找到"qi"子字符串第一次出现位置的索引 + int index6 = str.indexOf("qi",5);//找到索引5以后子字符串"qi"第一个出现位置所在索引 + System.out.println("子字符串qi第一次出现位置的索引号为:"+index5); + System.out.println("索引5以后子字符串qi第一次出现位置的索引号为:"+index6); + System.out.println("*****************"); + /***4、lastIndexOf()方法查找子字符串最后一次出现位置格式1,2***/ + int index7 = str.lastIndexOf("qi"); + int index8 = str.lastIndexOf("qi",5); + System.out.println("子字符串qi最后一次出现位置的索引号为:"+index7); + System.out.println("索引号5以后子字符串qi最后一次出现位置的索引号为:"+index8); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/NewStudent.java b/ruoyi-system/src/main/java/NewStudent.java new file mode 100644 index 000000000..afcd30b1d --- /dev/null +++ b/ruoyi-system/src/main/java/NewStudent.java @@ -0,0 +1,36 @@ +public class NewStudent { + /** + * 学生 + */ + private String name; + /** + * 名字 + */ + private String age;//定义 + + /** + * 年龄 + * @param inputName + * @param inputAge + */ + public NewStudent(String inputName,String inputAge){ + this.name = inputName; + this.age = inputAge; + } + public void eat(){ + System.out.println("吃饭"); + } + + /** + * 吃饭 + * @param food + */ + + public void eat(String food){ + System.out.println("学生吃的"+food); + } + public String eat(String food,String time){ + System.out.println("学生在" + time + "吃的" + food); + return"吃饱了";//定义吃饭的方法 + } +} diff --git a/ruoyi-system/src/main/java/Shape.java b/ruoyi-system/src/main/java/Shape.java new file mode 100644 index 000000000..e8f03ca49 --- /dev/null +++ b/ruoyi-system/src/main/java/Shape.java @@ -0,0 +1,6 @@ +/** + * 定义一个表示形状的接口 + */ +public interface Shape { + String name(); +} diff --git a/ruoyi-system/src/main/java/Square.java b/ruoyi-system/src/main/java/Square.java new file mode 100644 index 000000000..185d3c14f --- /dev/null +++ b/ruoyi-system/src/main/java/Square.java @@ -0,0 +1,9 @@ +/** + * 实现Shape接口的正方形类 + */ +public class Square implements Shape { + @Override + public String name() { + return "正方形"; + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/StringBufferDemo1.java b/ruoyi-system/src/main/java/StringBufferDemo1.java new file mode 100644 index 000000000..9f75a2764 --- /dev/null +++ b/ruoyi-system/src/main/java/StringBufferDemo1.java @@ -0,0 +1,107 @@ +/** + * @ClassName: StringBufferDemo1 + * @Description: StringBuffer 拼接字符串 + * 多线程操作大量数据,用StringBuffer。 + * StringBuffer 对方法加了synchronized(同步锁)或者对调用的方法加了同步锁,所以是线程安全的。 + * StringBuffer和StringBuilder这两个可变类的原理和操作基本相同。 + * @author: Zh + * @date: 2024/4/8 16:56 + */ +public class StringBufferDemo1 { + public static void main(String[] args) { + + /** + * 创建StringBuffer对象 + */ + + StringBuffer sb = new StringBuffer("孙悟空"); + + /** + * 在字符串后面追加新的字符串 + */ + + sb.append("会龟派气功"); + + /** + * StringBuffer对象:孙悟空会龟派气功 + */ + + System.out.println("StringBuffer对象:" + sb); + + /** + * 删除指定位置上的字符串,从指定的下标开始和结束,下标从0开始 + */ + + /** + * 0 孙 1悟 2空 3会 4龟 5派 6气 7功 + */ + + /** + * 2空 3会 + */ + + sb.delete(2, 4); + + /** + * delete删除:孙悟龟派气功 + */ + + System.out.println("delete删除:" + sb); + + /** + * 在指定下标位置上添加指定的字符串 + */ + + sb.insert(2, "123"); + System.out.println("insert新增:" + sb); // insert新增:孙悟123龟派气功 + + /** + * 将字符串翻转 + */ + + sb.reverse(); + + /** + * reverse反转:功气派龟321悟孙 + */ + + System.out.println("reverse反转:" + sb); + + + /** + * 将StringBuffer转换成String类型 + */ + + + String s = sb.toString(); + + /** + * String类型:功气派龟321悟孙 + */ + + check(s); // + + } + + + + /** + + * 检查传入的参数是否是String类型 + + * + + * @param abc + + */ + + public static void check(String abc) { + + System.out.println("String类型:" + abc); + + } + + + +} + diff --git a/ruoyi-system/src/main/java/StringBuilderDemo1.java b/ruoyi-system/src/main/java/StringBuilderDemo1.java new file mode 100644 index 000000000..02792b3ed --- /dev/null +++ b/ruoyi-system/src/main/java/StringBuilderDemo1.java @@ -0,0 +1,123 @@ +/** + * @ClassName: StringBuilderDemo1 + * @Description: StringBuilder 拼接字符串 + * 单线程操作大量数据,用StringBuilder。 + * StringBuilder 并没有对方法进行加synchronized(同步锁),所以是非线程安全的。 + * StringBuffer和StringBuilder这两个可变类的原理和操作基本相同。 + * @author: Zh + * @date: 2024/4/8 16:41 + */ + +public class StringBuilderDemo1 { + + public static void main(String[] args) { + // StringBuilder的字符串拼接.append + StringBuilder sb = new StringBuilder(); + + /** + * 字符 + */ + + sb.append("a"); + + /** + * 整数 + */ + + sb.append(1); + + /** + * 布尔类型 + */ + + sb.append(false); + + /** + * 小数 + */ + + sb.append(3.3); + + /** + * 字符串 + */ + + sb.append("abc"); + + /** + * append的应用:a1false3.3abc + */ + + System.out.println("append的应用:" + sb); + + StringBuilder sb1 = new StringBuilder(); + + /** + * 支持链式编程 + */ + + sb1.append("a").append("b").append("c").append("我爱你中国"); + + /** + * append支持链式编程:abc我爱你中国 + */ + + System.out.println("append支持链式编程:" + sb1); + + /** + * reverse反转 + */ + + sb1.reverse(); + + /** + * reverse反转:国中你爱我cba + */ + + System.out.println("reverse反转:" + sb1); + + /** + * 字符串长度length + * 字符串长度length:8 + */ + + System.out.println("字符串长度length:" + sb1.length()); + + /** + * 注意:StringBuilder只是拼接字符串的手段:效率好。 + * 最终的目的还是要恢复成String类型。 + */ + + StringBuilder sb2 = new StringBuilder(); + sb2.append("123").append("阿拉伯数字"); + + /** + * check(sb2); // 报错,因为sb2不是String类型 + * 拼接字符串:123阿拉伯数字 + */ + + System.out.println("拼接字符串:" + sb2); + + /** + * 恢复成String类型 + */ + + String rs = sb2.toString(); + + /** + * String类型:123阿拉伯数字 + */ + + check(rs); + } + + /** + * 检查传入的参数是否是String类型 + * + * @param abc + */ + + public static void check(String abc) { + System.out.println("String类型:" + abc); + } +} diff --git a/ruoyi-system/src/main/java/Student.java b/ruoyi-system/src/main/java/Student.java new file mode 100644 index 000000000..727b636ef --- /dev/null +++ b/ruoyi-system/src/main/java/Student.java @@ -0,0 +1,37 @@ +public class Student { + // 1.局部变量:在方法、构造函数或块内部声明的变量。 + public void run() { + String weight = "100斤"; // 局部变量weight,必须有初始值。 + // 因为实例变量age没赋值,所以默认是0 + System.out.println(name + "现在" + age + "岁"); // 小明现在0岁 + System.out.println(name + weight + ",跑得很快"); // 小明100斤,跑得很快 + } + + // 2.实例变量:在类中声明,但在方法、构造函数或块之外。 + public String name = "小明"; // 公有实例变量name对子类可见 + private int age; // 私有实例变量age,仅在该类可见,不赋值,默认是0 + + // main方法,程序入口 + public static void main(String[] args) { + Student.onLineNumber++; // 22 + System.out.println(onLineNumber); + Student student = new Student(); + student.run(); + student.eat("方便面"); + student.study(); + } + + // 3.类变量:在类中用 static 关键字声明的变量,它们属于类而不是实例。 + public static int onLineNumber = 21; + private String major = "计算机科学"; + + // 4.参数变量:是方法或构造函数声明中的变量 + public void eat(String food) { // 参数变量food + System.out.println(name + "喜欢吃" + food); // 小明喜欢吃方便面 + } + + // 自定义方法 + public void study() { + System.out.println(name + "正在学习" + major); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/Test.java b/ruoyi-system/src/main/java/Test.java new file mode 100644 index 000000000..e69de29bb diff --git a/ruoyi-system/src/main/java/TestArray.java b/ruoyi-system/src/main/java/TestArray.java new file mode 100644 index 000000000..7669f3419 --- /dev/null +++ b/ruoyi-system/src/main/java/TestArray.java @@ -0,0 +1,37 @@ +public class TestArray { + /** + * + * @param args + */ + public static void main(String[] args) { + // double类型的数组 + double[] scores = new double[]{99.5, 88.0, 75.5}; + double[] scores1 = {99.5, 88.0, 75.5}; // 简化写法 + + // int类型的数组 + int[] ages = new int[]{12, 24, 36}; + int[] ages1 = {12, 24, 36}; // 简化写法 + + int size = 5; // 设置数组大小是10 + String[] names = new String[size]; // 定义数组 + names[0] = "孙悟空"; + names[1] = "贝吉塔"; + names[2] = "弗利萨"; + names[3] = "沙鲁"; + names[4] = "魔人布欧"; + // 编译不报错,运行报错,因为数组大小是5,这是数组里第6个元素,数组越界ArrayIndexOutOfBoundsException + // names[5] = "布尔玛"; + // 数组索引从 0 开始,所以索引值从 0 到 arrayRefVar.length-1 + for (int i = 0; i < names.length; i++) { + System.out.print("索引:" + i + names[i] + " "); + } + + System.out.println(); + + // 数组变量名存储的是数组在内存种的地址,数组是引用类型 + // [ 指的是 数组 + // D 指的是 数据类型double + // @ 指的是 在哪里 + System.out.println(scores); // [D@776ec8df,指的是数组的十六进制地址 + } +} diff --git a/ruoyi-system/src/main/java/TestBook.java b/ruoyi-system/src/main/java/TestBook.java new file mode 100644 index 000000000..008b5b4b8 --- /dev/null +++ b/ruoyi-system/src/main/java/TestBook.java @@ -0,0 +1,22 @@ +/** + * 测试多态性的类 + */ + +import java.util.ArrayList; +import java.util.List; + +/** + * 测试类 演示多样性 + */ +public class TestBook { + public static void main (String[] args) { + List books = new ArrayList<>(); + Book literatureBook = new Literature(); + Book historyBook = new History(); + books.add(literatureBook); + books.add(historyBook); + for (Book book : books){ + System.out.println(book.name()); + } + } +} diff --git a/ruoyi-system/src/main/java/TestShape.java b/ruoyi-system/src/main/java/TestShape.java new file mode 100644 index 000000000..9ad97874c --- /dev/null +++ b/ruoyi-system/src/main/java/TestShape.java @@ -0,0 +1,22 @@ +/** + * 测试多态性的类 + */ + +import java.util.ArrayList; +import java.util.List; + +/** + * 测试类 演示多样性 + */ +public class TestShape { + public static void main(String[] args) { + List shapes = new ArrayList<>(); + Shape circleShape = new Circle(); // 创建Circle + Shape squareShape = new Square(); // 创建Square + shapes.add(circleShape); // 将Circle添加到列表中 + shapes.add(squareShape); // 将Square添加到列表中 + for (Shape shape : shapes) { // 遍历列表中的每个Shape对象 + System.out.println(shape.name()); // 打印 + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/TestTop.java b/ruoyi-system/src/main/java/TestTop.java new file mode 100644 index 000000000..7ce7487ad --- /dev/null +++ b/ruoyi-system/src/main/java/TestTop.java @@ -0,0 +1,13 @@ +public class TestTop { + public static void main(String[] args){ + Top topPerson = new Top("xx","20","2");//创建top对象 + topPerson.name(); + topPerson.age(); + topPerson.ranking();//输出 + + Top topPer = new Top("cc","21","1");//创建top对象 + topPer.name(); + topPer.age(); + topPer.ranking();//输出 + } +} diff --git a/ruoyi-system/src/main/java/Top.java b/ruoyi-system/src/main/java/Top.java new file mode 100644 index 000000000..d1603c70e --- /dev/null +++ b/ruoyi-system/src/main/java/Top.java @@ -0,0 +1,75 @@ +/** + * 表示排名的类 + */ +public class Top { + + /** + * 名字 + */ + private String name; + + /** + *年龄 + */ + private String age; + + /** + * 名次 + */ + private String ranking; + + /** + * 构造法 + * @param name + * @param age + * @param ranking + */ + public Top(String name,String age,String ranking){ + this.name=name; + this.age=age; + this.ranking=ranking; + } + + /** + * 获取名字 + */ + public void name() { + System.out.println("名字: " + name); + } + + /** + * 获取年龄 + */ + public void age() { + System.out.println("年龄: " + age); + } + + /** + * 获取名次 + */ + public void ranking() { + System.out.println("名次: " + ranking); + } + + /** + * 获取名字 + */ + public void name1() { + System.out.println("名字: " + name); + } + + /** + * 获取年龄 + */ + public void age1() { + System.out.println("年龄: " + age); + } + + /** + * 获取名次 + */ + public void ranking1() { + System.out.println("名次: " + ranking); + } + +} diff --git a/ruoyi-system/src/main/java/Word.java b/ruoyi-system/src/main/java/Word.java new file mode 100644 index 000000000..bd9798655 --- /dev/null +++ b/ruoyi-system/src/main/java/Word.java @@ -0,0 +1,12 @@ +public class Word { + public static void main(String[] args) { + int n = 7; + if (n >= 0 && n < 10) { + for (int i = 0; i < n; i++) { + System.out.println("He" + n + n +"o" + " Wor" + n + "d"); + } + } else { + System.out.println("n>10"); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/Wount.java b/ruoyi-system/src/main/java/Wount.java new file mode 100644 index 000000000..135c18f38 --- /dev/null +++ b/ruoyi-system/src/main/java/Wount.java @@ -0,0 +1,11 @@ +public class Wount { + public static void main(String[] args) { + String studentId = "20233011082"; + char lastDigit1 = studentId.charAt(studentId.length() - 2); + char lastDigit2 = studentId.charAt(studentId.length() - 1); + char[] lastTwoDigits = {lastDigit1, lastDigit2}; + for (char c : lastTwoDigits) { + System.out.print(c + " "); + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/ss.java b/ruoyi-system/src/main/ss.java new file mode 100644 index 000000000..cb6ca8ffe --- /dev/null +++ b/ruoyi-system/src/main/ss.java @@ -0,0 +1,30 @@ +//字符与字符串查找 +public class da{ + public static void main(String args[]){ + String str = "How qi bocome handsome like qi ge"; //定义一个长字符串 + System.out.println("该字符串为:"+str); + /***1、indexOf()方法查找字符首个出现位置格式1,2***/ + int index1 = str.indexOf(" "); //找到第一个空格所在的索引 + int index2 = str.indexOf(" ",4); //找到索引4以后的第一个空格所在索引 + System.out.println("第一个空格所在索引为:"+index1); + System.out.println("索引4以后的第一个空格所在索引为:"+index2); + System.out.println("*****************"); + /***2、lastIndexOf()方法查找字符最后出现位置格式1,2***/ + int index3 = str.lastIndexOf(" "); //找到最后一个空格所在的索引 + int index4 = str.lastIndexOf(" ",10);//找到索引10以后的第一个空格所在索引 + System.out.println("最后一个空格所在索引为:"+index3); + System.out.println("索引10以前最后一个空格所在索引为:"+index4); + System.out.println("*****************"); + /***3、indexOf()方法查找子字符串第一次出现位置格式1,2***/ + int index5 = str.indexOf("qi"); //找到"qi"子字符串第一次出现位置的索引 + int index6 = str.indexOf("qi",5);//找到索引5以后子字符串"qi"第一个出现位置所在索引 + System.out.println("子字符串qi第一次出现位置的索引号为:"+index5); + System.out.println("索引5以后子字符串qi第一次出现位置的索引号为:"+index6); + System.out.println("*****************"); + /***4、lastIndexOf()方法查找子字符串最后一次出现位置格式1,2***/ + int index7 = str.lastIndexOf("qi"); + int index8 = str.lastIndexOf("qi",5); + System.out.println("子字符串qi最后一次出现位置的索引号为:"+index7); + System.out.println("索引号5以后子字符串qi最后一次出现位置的索引号为:"+index8); + } +} \ No newline at end of file