字符逆序
Time Limit: 1000 ms
Memory Limit: 65536 KiB
Problem Description
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。
Input
输入包括一行。
第一行输入的字符串。
第一行输入的字符串。
Output
输出转换好的逆序字符串。
Sample Input
I am a student
Sample Output
tneduts a ma I
Hint
字符串的最后一个字符是n-1 而不是n 即第一个字符是0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str;
char s;
str = input.nextLine();
int i, j, n;
n = str.length();
for(i = n-1; i>= 0; i--) {
s = str.charAt(i);
System.out.print(s);
}
}
}
本文介绍了一种简单的字符串逆序算法实现方法,通过Java程序演示如何将输入的字符串进行逆序处理并输出结果。适用于初学者理解基本的字符串操作。
768

被折叠的 条评论
为什么被折叠?



