Java String Reverse

Sort by

recency

|

1922 Discussions

|

  • + 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.equals(s.toString())) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    
        /* Enter your code here. Print output to STDOUT. */
    
    }
    

    }

  • + 0 comments

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

    public class Main {

    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
    
        String A=sc.nextLine();
                char[] letra = new char[A.length()];
                char[] letra2 = new char[A.length()];
    
        for(int i=0; i<A.length(); i++){
    
            letra[i] = A.charAt(i);
        }
    
        int j = 0;
        for (int i = A.length() - 1; i >= 0; i--) {
            letra2[j] = A.charAt(i);
            j++;
        }
    
        boolean esPalindromo = true;
    
        for (int i = 0; i < A.length(); i++) {
            if (letra[i] != letra2[i]) {
                esPalindromo = false;
                break; 
            }
        }
    
        if (esPalindromo) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    
    
    
        sc.close();
    
    }
    

    }

  • + 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();
    boolean isPalindrome = true;
    int length = A.length();
    for (int i = 0; i < length / 2; i++) {
        if (A.charAt(i) != A.charAt(length - 1 - i)) {
            isPalindrome = false;
            break;
        }
    }
    System.out.println(isPalindrome ? "Yes" : "No");
    sc.close();
    

    } }

  • + 0 comments

    String res =""; for(int i = A.length()-1;i >=0; i--){ res = res+(A.charAt(i)); } if (res.equals(A)){ 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();
        String rev=null;
        sc.close();
        for(int i=A.length()-1; i>0;i--){
            rev = rev+A.charAt(i);
        }
        if(rev==A){
            System.out.println("yes");
        }
    }
    

    }