Yes. You've got the input and it's going into an array, right? So you need to
(1)loop over the input array, which you know how to do (lines 13-18 of your posted code) and
(2)check each member of the array to see that it's a palindrome (your current code only checks one of the words, the last one, but you know how to check that it's a palindrome) and
(3)put the result into an array of results, which you know how to do.

This suggests that you could have (1), (2), and (3) in the same loop, since you're doing the same thing to everything you handle, and the results should have the same index as the input.

So you see, you've got all the code. Now you just need to put it together so it does what you want. Have fun.

okay sir thank for this...i will write again if i have doubt sir...more power to you...

jemz, the program you are goint to make is working in this way:
The client has to input 4 words,
Then the program checks each individual word to see if it is palindrom.
If so, your outpu seems OK.
Am I right?

jon and jemz, I have just completed the program using StringBuffer method: reverse() to check palindrome. My attention is to show the usefullness of StringBuffer

import java.io.*;
import javax.swing.JOptionPane;
 public class Jemz1{   


 static boolean palindromeCouplet (String s)   {
 	StringBuffer s1 = new StringBuffer(s);
 return ((s.compareTo(new String(s1.reverse()))==0) ? true :false)  ;
 	}	

 public static void main(String[] args) {	
 	while(true){
    String str=JOptionPane.showInputDialog( null,  
	"Type in a word!\nPress cancel to ternimate。",
	"IS A PALINROME",
	JOptionPane.QUESTION_MESSAGE);    
    
	if (str == null) {
	System.out.println("Bey for now");
    	break;
    	} 
JOptionPane.showMessageDialog( null,  
	"Palindrome: " + palindromeCouplet(str),
	str + " IS A PALIDROME? ",
	JOptionPane.INFORMATION_MESSAGE);  
          }
      }   
}

jemz, the program you are goint to make is working in this way:
The client has to input 4 words,
Then the program checks each individual word to see if it is palindrom.
If so, your outpu seems OK.
Am I right?

yes sir, checking each words if its palindrome...string buffer i will try that your code sir after i have done mine...thank you for helping me sir...more power to you...

Yes. You've got the input and it's going into an array, right? So you need to
(1)loop over the input array, which you know how to do (lines 13-18 of your posted code) and
(2)check each member of the array to see that it's a palindrome (your current code only checks one of the words, the last one, but you know how to check that it's a palindrome) and
(3)put the result into an array of results, which you know how to do.

This suggests that you could have (1), (2), and (3) in the same loop, since you're doing the same thing to everything you handle, and the results should have the same index as the input.

So you see, you've got all the code. Now you just need to put it together so it does what you want. Have fun.

hello sir i have question about the step #1,loop over the inut array am i goin to add for loop like this

for(i=0;i<words.length;i++)
{
   for(i=0;i<words.length;i++)
   {  		  
       words[i]=console.next();

hoping for your positive responds...

After the program has receive 5 words inputed, the i became 5. The the program goes to line 22 : if(words.charAt(forward)!=words.charAt(backward))
and the index outbounds since you have defined the the length (size) of the String array "word" is 5.

Your code is able to check a series of strings a client inputs (in which we determine palindrome in terms of series of words) instead of one string (in which we determine palindrome in terms of characters).
I have modified your code as follows:

import java.io.*;
 public class jemz {
 	
 public static void main(String args[]){
  String []words = new String[5];
  Console console = System.console();
						
			int forward=0;
			int backward=words.length-1;
			int i;
			
			System.out.println("Input 5 words");
						
			for(i=0;i<words.length;i++)
			words[i]=new String(console.readLine("Input the " + (i+1) +" word:\n"));
								
			boolean found=true;
			while(forward<backward)	{
				if (words[forward].compareTo(words[backward]) != 0)	{
					found=false;
					break;					
				}
				
				forward++;
				backward--;								
			}
				if(found)
				System.out.println("palindrome");
		    	else
				System.out.println("Not Palindrome");			
		}
}

The testing output:
Input 5 words
Input the 1 word:
jemz
Input the 2 word:
loves
Input the 3 word:
JAVA
Input the 4 word:
loves
Input the 5 word:
jemz
palindrome

sir i have problem on this i always get arrayindexouofbounds..please help me sir.hoping for your positive responds..

if the user input this

jemz
jon
von
radar
pool

the output should like this.
jemz=not palindrome
jon=not palindrome
von=not palindrome
radar=palindrome
dood=palindrome

but i its not working i need your help sir...

String []words = new String[5];
			boolean found;
			int forward=0;
			int backward=words.length-1;
			int i;
			
			System.out.println("Input palindrome word");
			
			
		  
			for(i=0;i<words.length;i++)
			{
			  words[i]=console.next();
			  
			}
				
		  for(i=0;i<words.length;i++)
		  {
			found=true;
			
			while(forward<backward)
			{
			
				if(words[i].charAt(forward)!= words[i].charAt(backward))
				{
					found=false;
					break;
					
				}
				
				forward++;
				backward--;
			}	
				
		  }

1. String []words = new String[5];
4. int backward=words.length-1;
24. if(words.charAt(forward)!= words.charAt(backward))

You're initializing "backward" to 4, and then using it to index a string of arbitrary length. If String s = "jon", s.charAt(4) = arrayIndexOutOfBounds.

1. String []words = new String[5];
4. int backward=words.length-1;
24. if(words.charAt(forward)!= words.charAt(backward))

You're initializing "backward" to 4, and then using it to index a string of arbitrary length. If String s = "jon", s.charAt(4) = arrayIndexOutOfBounds.

hello sir it works for me,this...

System.out.println("Input palindrome word");
			
			
		  
			for(i=0;i<words.length;i++)
			{
			  words[i]=console.next();
			  
			}
      for(i=0;i<words.length;i++)
		  {
			found=true;	
			int forward=0;
			int backward=words[i].length()-1;
			while(forward<backward)
			{
			
				if(words[i].charAt(forward)!= words[i].charAt(backward))
				{
					found=false;
					break;
					
				}
				
				forward++;
				backward--;
			}

Bingo. Looks good from here. Well done.

Bingo. Looks good from here. Well done.

thank you sir...i would like to thank to all people who help me especially you sir Mr.jon.kiparsky and Mr.tong...more power to you all...

palindrome is a String instance or an array of char.
You ask the client to input one instance of String rather than an array of String.
Then you should process (work) on this instance to determine if it is polindrome or not. Therefore we are dealing with one instance of String only. We will compare the first char with the last char in the string.

thank you sir...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.