MulaiMulai sekarang secara gratis

Reversing!

You want to perform a practical joke on your website and replace words with their inverse. You are testing your method before deploying.

Latihan ini adalah bagian dari kursus

Intermediate Java

Lihat Kursus

Petunjuk latihan

  • Give the correct name for the method.
  • Enter the appropriate parameter type for the method.
  • Choose the correct starting value for i in the loop.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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));
  }
}
Edit dan Jalankan Kode