您的位置:首页 > 其它

字符串如何转变为倒叙

2016-04-05 17:46 417 查看
要求:把"a67b"进行倒叙;

分析:1.把字符串转换成 Char 类型的数组;

2.利用循环把它们转换位置;

public class Demo3 {

public static void main(String[] args) {

(1.把字符串转换成 Char 类型的数组;)

String a= "a67b";

char[] temp=a.toCharArray( );

(2.利用循环把它们转换位置;)

for (int x =0; x < temp.length / 2; x++){

char a1 = temp[x];

temp[x] = temp[temp.length - 1 - x];

temp [temp.length -1 - x] = a1;

}

System.out.println( String.valueOf(temp));

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: