Java String Reverse

Sort by

recency

|

1928 Discussions

|

  • + 0 comments

    Using "Two Pointers Technique":

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        String A=sc.next();
        int left = 0, right = A.length()-1;
    
        while(left < right) {
            if(A.charAt(left) != A.charAt(right)) {
                System.out.println("No");
                return;
            }
            left++;
            right--;
        }
    
        System.out.println("Yes");
    }
    

    }

  • + 0 comments

    Not able to submit the code even though all test cases are getting passed. It's showing error "Submission cannot be processed".

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        String A=sc.next();
        /* Enter your code here. Print output to STDOUT. */
        int start=0;
        int end=A.length()-1;
        boolean isPalindrome=true;
         while(start<=end){
            if(A.charAt(start)!=A.charAt(end)){
                isPalindrome=false;
                break;
            }else{
                start++;
                end--;
            }
        }
        System.out.println(isPalindrome?"Yes":"No");
        sc.close();
    
    }
    

    }

  • + 0 comments

    boolean isPalindrome = true;

        for (int i = 0; i < A.length() / 2; i++) {
            if (A.charAt(i) != A.charAt(A.length() - 1 - i)) {
                isPalindrome = false;
                break;
            }
        }
    
        if (isPalindrome) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }   
    
  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        String A=sc.next();
        StringBuffer s = new StringBuffer(A);
        s.reverse();
        if(A.compareTo(s.toString())==0)
         System.out.println("Yes");
        else
         System.out.println("No");
    
    
    }
    

    }