Q:

Java Program to reverse a string

0

Program to reverse a string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.*;
 
class demo1
{
   public static void main(String args[])
   {
      String before, reverse = "";
      Scanner in = new Scanner(System.in);
 
      System.out.println("Enter a string to reverse");
      before = in.nextLine();
 
      int l = before.length();
 
      for ( int i = l - 1 ; i >= 0 ; i-- )
         reverse = reverse + before.charAt(i);
 
      System.out.println("Reverse of entered string is: "+reverse);
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now