ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2016 ICSE Computer Science Paper



Share with a Friend

Solved 2016 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Palindrome or Special Word Program - ICSE 2016 Computer Science

Special words are those words which starts and ends with the same letter.
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.

import java.util.Scanner; class Check{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Enter the word: "); String w = in.next().toUpperCase(); String rev = ""; for(int i = w.length() - 1; i >= 0; i--) rev += w.charAt(i); if(w.equals(rev)) System.out.println("Palindrome"); else{ char first = w.charAt(0); char last = w.charAt(w.length() - 1); if(first == last) System.out.println("Special word"); else System.out.println("Not a special word"); } } }

Output

 
 OUTPUT 1: 
Enter the word: EXISTENCE
Special word 

 OUTPUT 2: 
Enter the word: MALAYALAM
Palindrome