How to reverse a string in java using scanner method?
Answers
Answered by
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>
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
Computer Science,
8 months ago
Economy,
8 months ago