Palindrome - System.out.println( "Enter a string and I...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import java.util.Scanner public class Palindrome { public static boolean checkstring(String S){ if(!S.isEmpty()){ int n = S.length() // checks if first and last char in string are equal if(S.charAt(0) == S.charAt(n-1)){ //if they are the same cuts off the first and last char and calls itself checkstring(S.substring(1, n-2)) } else{ return false } } return true } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println( "Enter a string and I will tell you how many vowels there are" ) String input = keyboard.next() // convert the string to all lower case for easier checking input = input.toLowerCase() if(!checkstring(input)) System.out.println("The String you entered is NOT a palindrome") else System.out.println("The String you entered is a palindrome") } }...
View Full Document

This note was uploaded on 09/16/2009 for the course CS 3345 taught by Professor Ozbirn during the Spring '08 term at University of Texas at Dallas, Richardson.

Ask a homework question - tutors are online