Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 5th, 2007, 10:01 PM   #1
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 416
Rep Power: 3 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Palindrome [Stupid rules]

Basically I have to write a program where the user can enter up to 30 characters and I have to check if the input is a palindrome. I did write this program and it works 100% however there is a catch... The professor wants us to store the input in char variables as in declare 30 chars and use that. What do you guys think is the least tedious way to accomplish this???

Thanks in advance.
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
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
Old Sep 5th, 2007, 10:23 PM   #3
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 416
Rep Power: 3 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Yes that would be the easy way to do it.... NO arrays are allowed. I can only use a string to get the input and then I have to store each character in a char.
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Sep 5th, 2007, 10:27 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Quote:
Originally Posted by Wizard1988 View Post
Yes that would be the easy way to do it.... NO arrays are allowed. I can only use a string to get the input and then I have to store each character in a char.
If that was his actual intention, I am truly disturbed.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Sep 5th, 2007, 10:29 PM   #5
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
Are you serious?!!? You actually have to DECLARE 30 char variables! Damn! Sorry dude... I don't have that much time. Honestly though, why would anyone need to do that!?
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Sep 5th, 2007, 10:31 PM   #6
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 416
Rep Power: 3 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
I am too... I am assuming that his goal is to make us appreciate arrays ect...
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Sep 5th, 2007, 10:45 PM   #7
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 369
Rep Power: 0 King is an unknown quantity at this point
Yea that seems pretty stupid. My teacher in high school did something similar to get us to appreciate arrays, but there is better ways then wasting a night doing a retarded program like that lol. Just hand it in with 5 variables and add a comment at the end saying the rest will look similar haha.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Sep 5th, 2007, 10:59 PM   #8
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 572
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Quote:
Originally Posted by Wizard1988 View Post
I am assuming that his goal is to make us appreciate arrays ect...
or he doesnt know that arrays make things easy and more efficient
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Sep 7th, 2007, 12:31 AM   #9
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 416
Rep Power: 3 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Like a monkey I just typed out around 600 lines of code and this shit ain't working. :mad:
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Sep 7th, 2007, 12:48 AM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I've known some very good and dedicated teachers, but there's a reason for the stereotype: Those who can, do; those who can't, teach.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple, contrived programming exercise DaWei Coder's Corner Lounge 16 Jun 14th, 2006 10:56 AM
Testing for a palindrome using std::string Jessehk C++ 9 May 3rd, 2006 1:55 AM
if the character string is palindrome ? eax Assembly 3 Apr 8th, 2006 12:16 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:42 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC