The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Homework - Array for Palindrome
Discuss Array for Palindrome in the Java Help forum on Dev Shed. Array for Palindrome Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 26th, 2012, 08:04 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 1
Time spent in forums: 6 m 5 sec
Reputation Power: 0
|
|
|
Homework - Array for Palindrome
Hi, I was wondering if anyone could help me with this. We were given the following layout and have to fill in the rest to make the array program for palindromes to work but I just can't get it to!
public class palindrome
{
public static void main(String[] args)
{
int i;
int j;
int palindromeSize=;//ENTER NUMBER OF LETTERS IN SUSPECTED PALINDROME
char palindrome[]=new char[palindromeSize];//Create array to hold the characters of a palindrome to be tested
//ENTER CHARACTERS OF PALINDROME INTO ARRAY
for)
}
{
palindrome[i]=inputCharacter;
}
System.out.print("The word or phrase to be tested is: ");
//traverse the array to print out the suspected palindrome
for()
{
;
}
System.out.println();
//A palindrom is tested by comparing first and last letter, second and second last letter etc until middle
for()
{
if()
{
System.out.println("and it is not a palindrome! ");
break;
}
if()//middle of word is reached
{
System.out.println("and it is a palindrome!");
}
}
}
}
|

November 26th, 2012, 08:24 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
Hi,
so what's your approach? What did you try? Where exactly did you have problems?
Please note that this is not a homework service, so we won't give you a solution for you to copy and paste or something. We can help you with concrete questions, but you have to do the actual programming.
|

November 26th, 2012, 08:29 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
It'd help if you'd edit your post and wrap the code in code tags.
|

November 26th, 2012, 09:07 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 29
Time spent in forums: 11 h 19 m 56 sec
Reputation Power: 0
|
|
Palidromes arent that diffucult. Since its fill in the blank, it makes it easier..
Now i do not know why you have an array for this activity. You could always just ask the user for a string, then give set that string to a string primitive..
Code:
System.out.println("Enter a string: ");
String value = scan.nextLine();
Then do a loop, which checks the string length and if the length is equal to one, then its a palindrome if not then simply have it loop through a comparison of the first letter with the last letter (best idea to use char and substring), then if it doesnt equal then break out of the loop and say its not a palindrome..
Hopefully that made some sense.
|

November 26th, 2012, 09:43 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Quote: | Originally Posted by cyimking Hopefully that made some sense. |
Great. You've basically repeated the code comments and the given layout.
Bursting in with a "solution" when others have just asked the OP for his own thoughts is also not very nice.
|

November 28th, 2012, 03:53 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 8
Time spent in forums: 1 h 28 m 48 sec
Reputation Power: 0
|
|
|
Array for Palindrome
I think Array are use for define any big size ratio in easiest way. Palindrome array is advance of array function.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|