蓝桥杯历年省赛真题
字符串
常见字符串函数与reverse
public class StringExamples {
public static void main(String[] args) {
String str = "Hello, World!";
System.out.println("Length of the string: " + str.length());
char firstChar = str.charAt(0);
System.out.println("First character: " + firstChar);
String subStr1 = str.substring(7);
String subStr2 = str.substring(7, 12);
System.out.println("Substring 1: " + subStr1);
System.out.println("Substring 2: " + subStr2);
int index = str.indexOf("World");
System.out.println("Index of 'World': " + index);
int lastIndex = str.lastIndexOf("l");
System.out.println("Last index of 'l': " + lastIndex);
boolean startsWith = str.startsWith("Hello");
System.out.println("Starts with 'Hello': " + startsWith);
boolean endsWith = str.endsWith("!");
System.out.println("Ends with '!': " + endsWith);
boolean isEmpty = str.isEmpty();
System.out.println("Is string empty: " + isEmpty);
String upperCaseStr = str.toUpperCase();
System.out.println("Uppercase string: " + upperCaseStr);
String lowerCaseStr = str.toLowerCase();
System.out.println("Lowercase string: " + lowerCaseStr);
String strWithSpaces = " Hello, World! ";
String trimmedStr = strWithSpaces.trim();
System.out.println("Trimmed string: '" + trimmedStr + "'");
String replacedStr = str.replace("World", "Java");
System.out.println("Replaced string: " + replacedStr);
String[] splitStr = str.split(", ");
System.out.println("Split string:");
for (String part : splitStr)