*5.46(倒排一个字符串)编写一个程序,提示用户输入一个字符串,然后以反序显示该字符串。 Enter a string: ABCD The reversed string is DCBA *5.46(Reverse a string) Write a program that prompts the user to enter a string and displays the string in reverse order. Enter a string: ABCD The reversed string is DCBA
参考代码:
package chapter05;
import java.util.Scanner;publicclassCode_46{publicstaticvoidmain(String[] args){
Scanner input =newScanner(System.in);
System.out.print("Enter a string : ");
String str = input.nextLine();
System.out.print("The reverse string is ");for(int i = str.length()-1;i >=0;i--){
System.out.print(str.charAt(i)+"");}}}
结果显示:
Enter a string : ABCD
The reverse string is DCBA
Process finished with exit code 0
第五章第四十六题(倒排一个字符串)(Reverse a string)*5.46(倒排一个字符串)编写一个程序,提示用户输入一个字符串,然后以反序显示该字符串。Enter a string: ABCDThe reversed string is DCBA*5.46(Reverse a string) Write a program that prompts the user to enter a string and displays the string in reverse order.En