Tuesday, 5 February 2019

1. How to find Reverse Sting in java.


Description:
Write a sample code to reverse String.

Code:
?
1
2
3
4
5
6
7
8

 import java.util.Scanner; public class ReverseString { public static void main(String[] args) { String Original, reverse = " "; Scanner s = new Scanner(System.in); System.out.println("Enter String for reverse:"); Original = s.nextLine(); int length = Original.length(); for (int i = length - 1; i >= 0; i--) reverse = reverse + Original.charAt(i); System.out.println("Rverse of entered String is:" + reverse); } }





Input:
Enter String for reverse: godblessgovind
Output:
Rverse of entered String is: dnivogsselbdog

No comments:

Post a Comment