I'll take a look at it. Can you post your new code?
I'll take a look at it. Can you post your new code?
<span style='color:black'> I am a part of all that I have met - Lord Tennyson</span>
<span style='color:blue'>Try not to let your mind wander...it is too small and fragile to be out by itself</span>
Here is your modified code. I modified it so it does what its suppose to. By now you must have understood the cases I mentioned earlier. I did this really quick and it should work but if you find a case that doesnt let me know so I will look at it more carefully. Although, I am sure this will work.
/*
Palindrome v1.0
#############Palindrome Revised###########
*/
import javabook.*;
public class Palin
{
public static void main (String[] args)
{
MainWindow mainWindow = new MainWindow("Palindromes");
InputBox inputBox = new InputBox(mainWindow);
OutputBox outputBox = new OutputBox(mainWindow);
outputBox.setVisible(true);
outputBox.printLine("---------Type stop! to quit program-------------");
String s1="";
String s2="";
char tempval=0;
char tempval2=0;
int n=0;
boolean userHalt=false;
while(userHalt==false)
{
s1 = inputBox.getString("Please type in a word: " );
s2 = s1.toUpperCase();
if(s1.equals("exit"))
{
userHalt=true;
break;
}
n=s2.length();
boolean pal= true;
for(int i=0; i<n/2; i++)
{
//n=s2.length(); /-> No Need for this (CHANGE MADE HERE)
tempval=s2.charAt(i);
tempval2=s2.charAt(n-i-1);
//CHANGES MADE HERE
if(tempval!=tempval2)
{
pal=false;
break;
}
}
//CHANGES MADE HERE
if(pal==true){
outputBox.printLine(s1 + " is a palindrome");
}
else
outputBox.printLine(s1 + " is not a palindrome");
}
}
}
<span style='color:black'> I am a part of all that I have met - Lord Tennyson</span>
<span style='color:blue'>Try not to let your mind wander...it is too small and fragile to be out by itself</span>
Thanks a lot
That works perfectly
One little thing though is that you should change the text displayed in the outputbox to "type exit" to stop the program.
On a given day or given circumstance, you think you have a limit.
And you then go for this limit and you touch this limit and you think "Ok, this is the limit".
As soon as you touch this limit, something happens and you suddenly can go a little bit further.
With your mind power, your determination, your instinct and the experience as well, you can fly very high.
- Ayrton Senna, R.I.P.
You are welcome.
Oh yes, I used "exit" to quit instead of stop!, but didnt change it in the display
<span style='color:black'> I am a part of all that I have met - Lord Tennyson</span>
<span style='color:blue'>Try not to let your mind wander...it is too small and fragile to be out by itself</span>
Bookmarks