How to reverse string in java ?

Program in short

Code

import java.util.*;
class A
{
public static void main(String[] args)
{
System.out.printf(new StringBuilder(new Scanner(System.in).next()).reverse().toString());
}
}

Output

Program in brief

Code

import java.util.*;
class A
{
public static void main(String[] args)
{
System.out.println(“Enter any String:->>”);
Scanner s=new Scanner(System.in);
String str=s.next();
StringBuilder strbul=new StringBuilder(str);
strbul.reverse();
System.out.print(“Reverse String ->> “+strbul);
}
}

Output

Leave a Reply