java从键盘输入一个字符串对该字符串逆转,先后输出逆转前后的字符串
2个回答
推荐于2017-09-20
展开全部
import java.util.*;
public class Egg{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String line = scan.nextLine();
scan.close();
System.out.println("逆转前:" + line);
String tmp = "";
for(int i = line.length() - 1; i >= 0; i--){
tmp += line.charAt(i);
}
System.out.println("逆转后:" + tmp);
}
}
2015-11-26
展开全部
String s;
System.out.println("字符串:"+s);
char[] array = s.toCharArray();
String reverse = "";
for (int i = array.length - 1; i >= 0; i--)
reverse += array[i];
System.out.println("逆转:"+reverse);
System.out.println("字符串:"+s);
char[] array = s.toCharArray();
String reverse = "";
for (int i = array.length - 1; i >= 0; i--)
reverse += array[i];
System.out.println("逆转:"+reverse);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询