lanbda reverse
Fri Jun 07 2024 12:53:28 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
import java.util.Scanner;
interface StringFunction {
String reverse(String input);
}
public class StringLambdaExample1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StringFunction reverseFunction = (str) -> {
String reversedString = "";
for (int index = str.length() - 1; index >= 0; index--) {
reversedString += str.charAt(index);
}
return reversedString;
};
String fixedString = " javaTpoint";
System.out.println("Reversed word using lambda function: " + reverseFunction.reverse(fixedString));
System.out.println("Enter a string to be reversed:");
String userInput = scanner.nextLine();
System.out.println("After reversing: " + reverseFunction.reverse(userInput));
scanner.close();
}
}
content_copyCOPY
Comments