There are 2 ways to reverse a string String reversal without using function String reversal with function String reversal without using function package stringReversal; import java.util.Scanner; public class StringReversal { int stringLength; static String stringToReverse; String reversedString=""; public String stringReverse(String name) { stringLength = name.length(); for(int i=stringLength-1; i>=0;i--) { reversedString+=name.charAt(i); } return reversedString; } public static void main(String[] args) { StringReversal stringReversal = new StringReversal(); Scanner scanner = new Scanner(System.in); System.out.print("Enter the string to reverse :"); stringToReverse = scanner.nextLine(); System.out.println("Reversed String is :" +stringReversal.stringReverse(stringToReverse)); } } Output Enter the string to reverse :Make the string reversed Reversed String is :desrever gnirts eht ekaM String ...
This site will be informative for history readers, technology explorers, Money making, and share market investors.