0

Q === WAP to take String and check String is palindrome or not (String is said to palindrome if reverse of sting is same as )

import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner (System.in) ; String s=sc.nextLine(); System.out.println("enter any string "); int i; char ch; String st=" "; for (i=0;i<s.length(); i++) { ch=s.charAt(i); st=ch+st; } if(st.equals(s)) { System.out.println(" palindrome "); } else {

12th Apr 2022, 8:16 AM
Tanay Rastogi
Tanay Rastogi - avatar
5 Respuestas
0
Your code looks incomplete, please LINK the complete code.
12th Apr 2022, 8:25 AM
Lisa
Lisa - avatar
0
And what is your question?
12th Apr 2022, 8:33 AM
Lisa
Lisa - avatar
0
check whether sting is palindrome or not(((String is said to palindrome if reverse of sting is same as original) Ex == MAM ,ARORA,ABBA
12th Apr 2022, 8:35 AM
Tanay Rastogi
Tanay Rastogi - avatar
0
Your code reverses the string. You could check if the reversed string equals the original string. Or loop through the string and compare current character if character at length - 1 - index. If it is a task in a sololearn course: The output must be exactly as in the task description.
12th Apr 2022, 8:38 AM
Lisa
Lisa - avatar