String reverser

Report a typo

Here is an interface StringReverser:

interface StringReverser {
    
    String reverse(String str);
}

You should create an anonymous class that implements the interface and assign the instance to the variable reverser. The anonymous class must override the method reverse of the interface. It should return the reversed input string.

Sample Input 1:

line

Sample Output 1:

enil

Sample Input 2:

aba

Sample Output 2:

aba
Write a program in Java 17
import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();

StringReverser reverser = /* create an instance of an anonymous class here,
do not forget ; on the end */

System.out.println(reverser.reverse(line));
}

interface StringReverser {

String reverse(String str);
}

}
___

Create a free account to access the full topic