Write a program to find that given number or string is palindrome or not

Write a program to find that given number or string is palindrome or not

Explanation :

Hello friends i hope you like my previous post, in today’s post we are going discuss about Write a program to find that given number or string is palindrome or not

so you have to Write a program to find that given number or string is palindrome or not (we have to take string from user)

so now let’s discuss the logic, how you can implement it

you have to take string from user so you have to make use of Scanner class and store the user input in string variable “str

note : make sure you use of next() method for scanning user input

so logic you have to use is, string you got from user input reverse it using reverse() method and compare the reversed String with the original input if it matched the it’s palindrome else it’s   not-palindrome

now create one String variable “rvs” to store the reversed string and store the reversed string in it [Ex: String rvs = new StringBuffer(str).reverse().toString(); ]

then use one if condition to validate whether it is palindrome or not for that we have to use equals() method [Ex: if(str.equals(rvs)){  } ]

if “if” condition is true than print It is palindrome “else” It is not palindrome using System.out.println();

Check Out other post – Write a program to count the number of words that start with capital letters

so here your program’s solution, check program below the post for reference

these are the java basic programs based on gtu syllabus

Program :

OUTPUT :

Write a program to find that given number or string is palindrome or not

Add a Comment

Your email address will not be published. Required fields are marked *