You are viewing a single comment's thread. Return to all comments →
public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String A=sc.next(); sc.close(); String[] str = A.split(""); int i=0; int j=(str.length)-1; boolean flag= true; while(i<j){ if (str[i].compareTo(str[j]) !=0){ flag=false; break; } i++; j--; } if(flag==true){ System.out.println("Yes"); } else if(flag==false){System.out.println("No");} } }
public class Solution {
public static void main(String[] args) { Scanner sc=new Scanner(System.in); String A=sc.next(); sc.close(); int i=0; int j=(A.length())-1; boolean flag= true; while(i<j){ if (A.charAt(i) != A.charAt(j)){ flag=false; break; } i++; j--; } if(flag==true){ System.out.println("Yes"); } else if(flag==false){System.out.println("No");} }
}
`
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Java String Reverse
You are viewing a single comment's thread. Return to all comments →
Language: Java 15
Using Array:Using CharAt Method:
public class Solution {
}
`