此代码的可能伪代码是什么?
我尝试了以下
代码:
import java.util.ArrayList;
import java.util.Scanner;
public class ReadingDataFromTheUser {
public static void main(String[] args) {
String input;
ArrayList <String> words = new ArrayList <String>();
Scanner scan = new Scanner (System.in);
do {
System.out.println("Enter a word or enter q to terminate program: ");
input = scan.nextLine();
words.add(input);
}while (!input.equalsIgnoreCase("q"));
int size =(words.size()-1);
for (int index=0; index<size;index++) {
String string;
String reverseWord ="";
string = words.get(index);
for (int value = string.length()-1; value>=0;value--) {
reverseWord+=string.charAt(value);
}
System.out.println(reverseWord);
}
scan.close();
}
}
答案 0 :(得分:1)
我会用这种方式写的。
1. Start
2. Read word as string
3. Take reverse as string
4. Take i
5. For (i=word.length-1; i>=0; i--)
do
1. Take ch = word.charAt(i)
2. reverse += ch
done
6. Print reverse
7. Stop
希望这有帮助。