Java String Reverse

Sort by

recency

|

1912 Discussions

|

  • + 0 comments

    In java strings are considered as objects which makes them different than other primitive datatypes like int, float, etc. and we cant use "==" to compare 2 strings with each other thus we used str1.equals(str2) here for comparision of the strings

  • + 0 comments

    Easy and short way:

    Scanner sc=new Scanner(System.in);
            String A=sc.next();
            /* Enter your code here. Print output to STDOUT. */
            String reverseString = new StringBuilder(A).reverse().toString();
            
            if(reverseString.equals(A)){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
    
  • + 0 comments

    public static String palindrome(String A){ for(int i=0; i

  • + 0 comments

    Here is Java String Reverse solution - https://programmingoneonone.com/hackerrank-java-string-reverse-problem-solution.html

  • + 0 comments

    String A = sc.next(); char [ ] str = A.toCharArray();

        int flag = 0;
    
        for(int i = 0;i<str.length/2;i++){
            if(str[i] == str[str.length-i-1]){
                flag += 1;
            }
        }
    
        System.out.println(flag == str.length/2?"Yes":"No");