Friday, 19 January 2018

Write a Java Program to Reverse of a String

package com.tutorial4u;

import java.util.Scanner;

public class ReverseString {
     public static void main(String[] args) {
           Scanner sc  = new Scanner(System.in);
           System.out.print("Enter any String : ");
           String str = sc.nextLine();
           String reverseString = "";
           System.out.print("Revesre string is : ");
           for(int i = str.length()-1 ; i>=0;i--){
                reverseString = reverseString+Character.toString(str.charAt(i));
           }
           System.out.println(reverseString);
     }

}


Output:

Enter any String : Tutorial4u
Revesre string is : u4lairotuT

No comments:

Post a Comment

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...