View Single Post
Old Sep 5th, 2007, 10:21 PM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
How are you getting the input? Scanner class? Does the professor want you to capture each char the user enters and store in a char array?

Here what I've would done
//imports, class naming, etc...w/e!

public static void main(String[] args)
{
	java.util.Scanner scanner = new java.util.Scanner(System.in);
	
	char[] input = scanner.next().toCharArray();
	if(input.length > 30)
		throw new Exception("TOO BIG!!!");
	
	char[] reverseInput = new char[input.length];

	for(int x = 0, i = input.length -1; i > 0; i--, x++)
		reverseInput[x] = input[i];

	for(int x = 0; x < input.length; x++)
	{
		if(reverseInput[x] != input[x])
		{
			System.out.prinln("Not a Palindrome!");
			System.exit(0);
		}
	}
	System.out.prinln("It's a Palindrome!");
		
}
I did not compile it so there might be errors but that is along the lines of what I would do. I don't know if you're allowed to do this.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote