java编程:要求用户输入一个字符串,按相反顺序输出该字符串.如输入abcd,输出dcba

2024-12-03 17:59:58
推荐回答(1个)
回答1:

package tourismsystem;

import java.util.Scanner;

public class TestP {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();

for(int i = line.length() - 1; i >= 0; i--){
System.out.print(line.charAt(i));
}
}

}