Advertisements
Advertisements
प्रश्न
Define a class to accept a string, convert it into lowercase and check whether the string is a palindrome or not.
A palindrome is a word that reads the same backward as forward.
Example:
madam, racecar etc.
Advertisements
उत्तर
public class Palindrome
{
public static void main(String args[])
{
String a, b = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter the string you want to check:");
a = s.nextLine();
a = a.toLowercase();
int n = a.length();
for{int i = n - 1; i >= 0; i--)
{
b = b + a.charAt(i);
}
if( a;equalsIgnoreCase(b))
{
System.out.println("The string is palindrome.");
}
else
{
System. out.println("The string is not a palindrome.");
}
}
}APPEARS IN
संबंधित प्रश्न
Write the return data type of the following function:
endsWith( )
Define a class to accept two strings, convert them into uppercase, check and display whether two strings are equal or not, if the two strings are not equal, print the string with the highest length or print the message both the strings are of equal length.
The String class method to join two strings is ______.
Give the output of the following String class method:
"COMMENCEMENT".lastIndexOf('M')Give the output of the following String class method:
"devote". compareTo("DEVOTE")int x = 98; char ch = (char)x; what is the value in ch?
The output of the statement "CONCENTRATION" indexOf('T') is ______.
The output of the statement "talent". compareTo("genius") is ______.
The following code to compare two strings is compiled, the following syntax error was displayed - incompatible types - int cannot be converted to boolean.
Identify the statement which has the error and write the correct statement. Give the output of the program segment.
void calculate()
{
String a="KING",b="KINGDOM";
boolean x=a.compareTo(b);
system.out.println(x);
}Consider the array given below:
char ch[]={'A','E','I','O','U'};
Write the output of the following statements:
System.out.println(ch[0]*2);;