Results 1 to 7 of 7
  1. #1
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    0

    Default Detecting Palindrome Program

    My question is stated in the picture highlighted in yellow.
    Attached Thumbnails Attached Thumbnails Detecting Palindrome Program-image.jpg  

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Detecting Palindrome Program

    Can you copy the code and post it here with your questions?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    0

    Default Re: Detecting Palindrome Program

    Okay

  4. #4
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    0

    Default Re: Detecting Palindrome Program

    The question is within the code, you won't miss it because I put a lot of question marks at the end of the question.

    Java Code:
    // variable declarations (and some initializations)
            Scanner keys = new Scanner(System.in);
            // now the program logic ...
            // Get the input from the user and convert to lowercase
            System.out.print("Please enter characters: ");
            String inputFromUser = keys.nextLine();
            String input = inputFromUser.toLowerCase();
    
            // start answer as 'true' and try to make it 'false'
            boolean answer = true; // boolean is set as true
            int i = 0; // starts at beginning & will move to right
            int j = input.length() - 1; // starts at the end, moves left
    
            // loop through all the characters...
            while (i < j) {
                // take care of spaces on the left
                char cL = input.charAt(i);
                while (!Character.isLetter(cL)) { //The program will execute the codes i++ and cL = input.charAt(i) only if the Boolean expression is true?????????????
                    i++; // move to the right
                    cL = input.charAt(i);
                }
                // take care of spaces on the right
                char cR = input.charAt(j);
                while (!Character.isLetter(cR)) { //The program will execute the codes j-- and cR = input.charAt(i) only if the Boolean expression is true?????????????
                    j--; // move to the left
                    cR = input.charAt(j);
                }
    
                if (cL != cR) {
                    answer = false;
                }
                System.out.println(i + " matches " + j + " " + answer);
                i++;
                j--; // move comparison closer to middle // Will the program always add and subtract from 'i' and 'j'?????????????????
            }
    
            // if it never was false, it's true!
            if (answer == true) {
                System.out.println("Palindrome !!!");
            } else {
                System.out.println("sorry, nothing...   :(");
            }
        } // end of main() method 
    } // end of Palindrome class
    Last edited by csanch11; 11-28-2013 at 01:10 AM.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Detecting Palindrome Program

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Also post your questions.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    0

    Default Re: Detecting Palindrome Program

    Okay I edited it.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Detecting Palindrome Program

    The ??? are too far to the right to view with the code that they are talking about. The formatting of the code by the site makes it hard to see the code and the comments at the same time.

    What happens when the code is compiled and executed?
    Copy the program's output here to show what it does.
    Last edited by Norm; 11-28-2013 at 01:27 AM.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Palindrome Test Program
    By Zelaine in forum New To Java
    Replies: 5
    Last Post: 08-27-2013, 03:22 AM
  2. Palindrome Program
    By e.cummins95 in forum New To Java
    Replies: 7
    Last Post: 03-09-2012, 12:59 AM
  3. Palindrome Prime program
    By Zora in forum New To Java
    Replies: 7
    Last Post: 10-19-2011, 08:42 PM
  4. Palindrome program
    By trinity in forum New To Java
    Replies: 4
    Last Post: 04-16-2011, 03:22 AM
  5. Palindrome program help
    By Nel in forum New To Java
    Replies: 1
    Last Post: 03-03-2011, 03:49 AM

Posting Permissions

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