判断是否为回文字符串
package String;import java.util.Scanner;
public class Demo_10 {public static void main(String[] args) {String str;Scanner sc = new Scanner(System.in);System.out.println("请输入一个字符串:");str = sc.next();StringBuilder sb = new StringBuilder(str).reverse();String result = sb.toString();if (result.equals(str)) {System.out.println("是回文字符串");} else {System.out.println("不是回文字符串");}}
}
字符串的拼接
package String;
public class Demo_11 {public static void main(String[] args) {int []arr={1,2,3};StringBuilder sb=new StringBuilder();sb.append("[");for (int i = 0; i < arr.length; i++) {sb.append(arr[i]);if(i<arr.length-1){sb.append(", ");}}sb.append("]");String result = sb.toString();System.out.println(result);}
}