Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

String Reverse Program in Java.

// java program to reverse a word
  
import java.io.*;
import java.util.Scanner;
  
class GFG {
    public static void main (String[] args) {
        
        String str= "Geeks", nstr="";
        char ch;
        
      System.out.print("Original word: ");
      System.out.println("Geeks"); //Example word
        
      for (int i=0; i<str.length(); i++)
      {
        ch= str.charAt(i); //extracts each character
        nstr= ch+nstr; //adds each character in front of the existing string
      }
      System.out.println("Reversed word: "+ nstr);
    }
}
  
//Contributed by Tiyasa
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #String #Reverse #Program
ADD COMMENT
Topic
Name
2+7 =