public class OOPTest06 {
public static String reverse(String str,int startIndex,int endIndex) {
char[] charArray = str.toCharArray();
while (startIndex<endIndex){
char temp = charArray[startIndex];
charArray[startIndex] = charArray[endIndex];
charArray[endIndex] = temp;
startIndex++;
endIndex--;
}
return String.valueOf(charArray);
}
public static void main(String[] args) {
String name ="abcdefghi";
String reverse = OOPTest06.reverse(name, 4, 7);
System.out.println(reverse);
}
}
使用java基础,简洁高效实现数组指定索引范围内元素的翻转
最新推荐文章于 2024-08-30 18:40:43 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)