Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
Strings are sequences of characters and are considered objects in Java. You can perform a wide variety of operations on a String object. Reversing a string object is one of the most commonly used operations.
Below is the Java program that prints the given string in reverse order.
import java.util.Scanner;
public class Reverse
{
public static void main(String[] args)
{
System.out.println("Enter a string you want to reverse:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String rev = "";
for(int i = str.length() - 1; i >= 0; i--)
{
rev = rev + str.charAt(i);
}
System.out.println("Reversed String:");
System.out.println(rev);
}
}
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.