java输入1234输出4321

要求用while语句例如我输入123456789 程序就输出987654321

import java.util.Scanner;

public class Demo001 {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
System.out.println("请输入字符串:");

String strString = scan.nextLine();

char array[] = strString.toCharArray();

int i = 0;
// while循环
while (i < strString.length())
{
System.out.print(array[array.length - i - 1]);
i++;
}
}
}

运行结果:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-09-22
import java.util.Scanner;
public class InputTest{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
StringBuffer str=new StringBuffer(sc.nextLine());
System.out.println(str.reverse());
}
}
请采纳答案,支持我一下。本回答被提问者采纳