Ad
Code
Diff
  • public class Practice01{
    	public static String reverse(String input) {
        char[] chars = input.toCharArray();
        for(int i = 0, j = input.length() - 1; i < j; i++, --j) {
          char t = chars[i];
          chars[i] = chars[j];
          chars[j] = t;
        }
        
        return new String(chars);
    	}
    }
    
    • //import java.util.Scanner;
    • public class Practice01{
    • public static String reverse(String input) {
    • /*Scanner sc = new Scanner(System.in);
    • System.out.println("Give the desired string to be reversed :");
    • String e = sc.nextLine();*/
    • String result = "";
    • for(int i = input.length() - 1; i >= 0; i --){
    • result += input.substring(i , i + 1);
    • char[] chars = input.toCharArray();
    • for(int i = 0, j = input.length() - 1; i < j; i++, --j) {
    • char t = chars[i];
    • chars[i] = chars[j];
    • chars[j] = t;
    • }
    • return result;
    • return new String(chars);
    • }
    • }