Java String Reverse

  • + 0 comments

    My code

    public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */

        Scanner input = new Scanner(System.in);
        String s = input.nextLine();
    
        String a = "";
        String b = "";
        for(int i=0; i<s.length(); i++){
            a = a+s.charAt(i);  
        }
    
        for(int j = s.length()-1; j>=0; j--){
            b= b+s.charAt(j);
        }
    
        if(a.equals(b)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }    
    }