反轉!
你想在網站上開個小玩笑,把單字替換成它們的反轉版本。你正在部署前先測試你的方法。
本練習屬於課程
Java 中級
練習說明
- 填入正確的方法名稱。
- 輸入此方法適當的參數型別。
- 在迴圈中選擇
i的正確起始值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
class StringReverser {
// Give the correct name and parameter type for the method
static String ____(____ toReverse) {
String tmp = "";
// Give the appropriate starting value for i
for (int i = ____.____ - 1; i >= 0; i--) {
tmp += toReverse.charAt(i);
}
return tmp;
}
public static void main(String[] args) {
String word = "stressed";
System.out.println(reverse(word));
}
}