Write a Program to reverse the string using the algorithm

 Write a Program to reverse the string using the algorithm

public class RevStrAlgo {
    public static void main(String[] args) {
        String str = "Harry Potter";
        String rev = "";

        int len = str.length();

        for(int i = len-1;i>0;i--){
            rev = rev + str.charAt(i);
        }

        System.out.println("Real String : "+ str);
        System.out.println("Reversing ke baad : " + rev);
    }    
}

Output of Program :


Comments