Alternative method to display the String in reverse form

Accept and display the String in reverse form

import java.util.Scanner//Calling Scanner Class
public class Reverse
{
    public static void main(String []args)
    {
        System.out.println("Enter String to Reverse it "); //Instruction to user
        String str= new Scanner(System.in).nextLine(); //Getting String from User
        int istr.length()//Calculating Length of Given String
        String rev=""; //Declaring and Initializing variable
            for(int j=i-1; j>=0; j--) //Looping statement
            {
                revrev+str.charAt(j); //Processing
            }
         //Printing Result
        System.out.println("Reverse of given String is ");
        System.out.println(rev);
    }
}

This program is used to display the string from the backward. If you haven't visited the other way to display the string in reverse form then, follow the link below:-

Output:

Comments

Popular posts from this blog

Java Program to make a comparison between numbers

Java program using Scanner Class

Java program to print 'Hello World'