Computer Science, asked by dimzokim2024, 1 year ago

How to reverse a string in java using scanner method?

Answers

Answered by Anonymous
1
<pre>
import java.util.Scanner;
public class ReverseString{ public static void main(String[] args) { System.out.println("Enter string to reverse:"); Scanner read = new Scanner(System.in); String str = read.nextLine(); StringBuilder sb = new StringBuilder(str); System.out.println("Reversed string is:"); System.out.println(sb.reverse().toString()); }}</pre>
Similar questions