ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2007 ICSE Computer Science Paper



Share with a Friend

Solved 2007 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Palindrome Program - ICSE 2007 Computer Science

Write a program using a method palin(), to check whether a string is a palindrome or not. A palindrome is a string that reads the same from left to right and vice-versa.
Example: MADAM, ARORA, ABBA

import java.io.*; class Palindrome{ public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("String: "); String s = br.readLine(); if(palin(s)) System.out.println(s + " is palindrome."); else System.out.println(s + " is NOT palindrome."); } public static boolean palin(String w){ String rev = ""; for(int i = w.length() - 1; i >= 0; i--) rev += w.charAt(i); return w.equalsIgnoreCase(rev); } }

Output

 
 OUTPUT : 
String: MADAM
MADAM is palindrome.