Page 450 - CA_Blue( J )_Class10
P. 450
System.out.print(k + " ");
k++;
}
System.out.println();
}
break;
case 2:
for(i = 1; i <= str.length(); i++)
{
System.out.println(str.substring(0, i));
}
break;
default:
System.out.println("Wrong Choice");
}
}
}
21. Special words are those words which starts and ends with the same letter. [2016]
Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.
Examples:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes.
Write a program to accept a word and check and print whether the word is a palindrome or only special word.
Ans. import java.util.*;
class Specialpalindrome
{
int specialword(String str)
{
if(str.charAt(0) == str.charAt(str.length() - 1))
return 1;
else
return 0;
}
int palinword(String str)
{
String tempstr = "";
int i;
tempstr = str.charAt(i) + tempstr;
if(str.equals(tempstr))
return 1;
else
return 0;
}
void main()
{
Scanner sc= new Scanner(System.in);
String wd;
448448 Touchpad Computer Applications-X

