字符串逆转
目录:
- 逆序输出一段话,如输入"I want to change the world",则输出"world the change to want I"。
- 将数组的后面若干位换到前面,如将0123456789变为6789012345。
Java源码:
/*
* shsheng
*/
package Programing;
public class ReversalString {
public static void main(String[] args) {
System.out.println(reversalStr("I want to change the world",' '));
System.out.println(reversalNum("0123456789",7));
}
public static void swap(char[] array,int i,int j){
if(i!=j){
char tmp=array[i];
array[i]=array[j];
array[j]=tmp;
}
}
public static void reversal(char[] array,int start,int end){
while(start