摘要: 使用 StringBuilder public class StringConcatenationUsingStringBuilder { public static void main(String[] args) { String str1 = "Hello"; String str2 = " 阅读全文
posted @ 2025-02-20 20:00 吉尼泰梅 阅读(5) 评论(0) 推荐(0)
摘要: 使用 concat() 方法 public class StringConcatenationUsingConcat { public static void main(String[] args) { String str1 = "Hello"; String str2 = " World"; / 阅读全文
posted @ 2025-02-20 20:00 吉尼泰梅 阅读(6) 评论(0) 推荐(0)
摘要: 将一个字符串加在另一个字符串末尾,不覆盖 public class StringConcatenationUsingPlus { public static void main(String[] args) { String str1 = "Hello"; String str2 = " World 阅读全文
posted @ 2025-02-20 20:00 吉尼泰梅 阅读(9) 评论(0) 推荐(0)
摘要: 递归方式 public class MaxInArrayRecursive { public static void main(String[] args) { int[] array = {12, 45, 67, 23, 9, 55}; int max = findMaxRecursive(arr 阅读全文
posted @ 2025-02-20 19:58 吉尼泰梅 阅读(8) 评论(0) 推荐(0)
摘要: Java 8 的 Stream API import java.util.Arrays; public class MaxInArrayWithStream { public static void main(String[] args) { int[] array = {12, 45, 67, 2 阅读全文
posted @ 2025-02-20 19:58 吉尼泰梅 阅读(10) 评论(0) 推荐(0)
摘要: 数组最大值(遍历循环) public class MaxInArray { public static void main(String[] args) { int[] array = {12, 45, 67, 23, 9, 55}; int max = findMax(array); System 阅读全文
posted @ 2025-02-20 19:58 吉尼泰梅 阅读(8) 评论(0) 推荐(0)
摘要: 使用 while 循环 public class SumOfDivisibleByThreeWithWhile { public static void main(String[] args) { int sum = 0; int i = 3; // 当 i 小于等于 100 时执行循环 while 阅读全文
posted @ 2025-02-20 19:41 吉尼泰梅 阅读(8) 评论(0) 推荐(0)
摘要: 计算1到100之间所有能被3整除的数的和、 public class SumOfDivisibleByThree { public static void main(String[] args) { int sum = 0; // 遍历 1 到 100 的所有数 for (int i = 1; i 阅读全文
posted @ 2025-02-17 23:55 吉尼泰梅 阅读(11) 评论(0) 推荐(0)
摘要: 使用 while 循环 public class EvenSumWithWhile { public static void main(String[] args) { int sum = 0; int i = 2; // 当 i 小于等于 100 时执行循环 while (i <= 100) { 阅读全文
posted @ 2025-02-17 23:54 吉尼泰梅 阅读(10) 评论(0) 推荐(0)
摘要: 优化 for 循环(直接遍历偶数) public class EvenSumOptimized { public static void main(String[] args) { int sum = 0; // 直接从 2 开始,每次递增 2,只遍历偶数 for (int i = 2; i <= 阅读全文
posted @ 2025-02-17 23:54 吉尼泰梅 阅读(7) 评论(0) 推荐(0)