Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: Java Help (programming)

  1. #21
    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>

  2. Software & Hardware   -   #22
    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.




    /*
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 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&#33; 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();&nbsp; /-> No Need for this (CHANGE MADE HERE)
    tempval=s2.charAt(i);
    tempval2=s2.charAt(n-i-1);

    //CHANGES MADE HERE
    if(tempval&#33;=tempval2)
    &nbsp; {
    &nbsp; pal=false;
    &nbsp; break;
    &nbsp; }

    }

    //CHANGES MADE HERE
    if(pal==true)
    {
    &nbsp; 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>

  3. Software & Hardware   -   #23
    Poster
    Join Date
    Jan 2004
    Posts
    3,073
    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 &quot;Ok, this is the limit&quot;.
    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.

  4. Software & Hardware   -   #24
    You are welcome.

    Oh yes, I used "exit" to quit instead of stop&#33;, 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>

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •