[go: up one dir, main page]

0% found this document useful (0 votes)
4 views1 page

Solutions - Palindrome String - Que-1

The document provides a Java program that checks if a given string is a palindrome, ignoring case differences. It includes an example of how to use the program and explains the logic behind reversing the string for comparison. The program utilizes the Scanner class for input and outputs whether the string is a palindrome or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Solutions - Palindrome String - Que-1

The document provides a Java program that checks if a given string is a palindrome, ignoring case differences. It includes an example of how to use the program and explains the logic behind reversing the string for comparison. The program utilizes the Scanner class for input and outputs whether the string is a palindrome or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

For Class 10 # Created by Prashant Tandon, Computer Teacher, SMC Kanpur # Mobile 9839575830

Answers – String Based Questions


Q1. Write a program to check whether the given string is a Palindrome String or not.
The input string to be checked irrespective of the case (Capital or Small Letter).
Example of Palindrome String: “MADAM”, “NITIN”, “Nitin”, “Arora”, “1331”, “RaceCar”

Note : The following answer also works with … “Arora”, “1331”, “RaceCar”
as we used equalsIgnoreCase( )

A1. import java . util . * ;

class PalindromeString
{
public static void main( )
{
Scanner SC = new Scanner ( System.in ) ;

System.out.print ( " Enter any String : " );


String str = SC . nextLine( ) ;

System.out.println ( " Given String : " + str );

int len, k ;
char ch ;

len = str.length() ;

String hold = "" ;

for( k = len-1 ; k >= 0 ; k-- )


{
ch = str.charAt( k );
hold = hold + ch ;
} // end of for loop

if( str.equalsIgnoreCase( hold ) == true )


System.out.println ( str + " - is a Palindrome" );
else
System.out.println ( str + " - is not a Palindrome" );

} // end of main function


} // end of class

Page No 1 of 1

You might also like