Ad
Code
Diff
  • //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);
        }
        return result;
    	}
    }
    
    • import java.util.ArrayList;
    • import java.util.Scanner;
    • import java.util.Collections;
    • public class Pratice01{
    • public static void main(String[] args) {
    • ArrayList<Character> arr = new ArrayList<>();
    • Scanner sc = new Scanner(System.in);
    • //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();
    • int f = e.length();
    • for(int i= 0;i<f;i++){
    • Character d = e.charAt(i);
    • arr.add(d);
    • }Collections.reverse(arr);
    • String k = "";
    • for(Character a:arr) {
    • String p = k+a;
    • String z = new StringBuilder().append(p).toString();
    • System.out.print("Reversed string"+z);
    • }
    • String e = sc.nextLine();*/
    • String result = "";
    • for(int i = input.length() - 1; i >= 0; i --){
    • result += input.substring(i , i + 1);
    • }
    • return result;
    • }
    • }