Results 1 to 5 of 5
  1. #1
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

    Default AHH How do i do this????

    Write a program that allows the user to enter in a String, then outputs an accurate statement about whether it is a palindrome or not.

    This method will take a string text as an argument and return true if text is a palindrome (the same when read forward or backwards, as in “Madam, I’m Adam”). In testing for a palindrome, ignore all spaces, punctuation marks, apostrophes, and other non-alphanumeric characters, and consider upper- and lowercase letters the same. Don’t let your method change the original string

    my code that has compile times errors on the method :

    [code]
    import java.util.Scanner;
    public class palindromette{
    public static void main (String[] args) {


    String user_input;
    Scanner scan = new Scanner(System.in);
    System.out.println ("Welcome to the Palindrome Application!");
    System.out.println ("This application will determine whether or not your input is a palindrome.");
    System.out.print ("Please enter a string:");
    user_input = scan.next();
    palindrome
    boolean palindromeTest (String input) {
    int left_side = 0;
    int right_side = input.length() - 1;
    while ((input.charAt(right_side) == input.charAt(left_side)) && (right_side > left_side)) {
    right_side--;
    left_side++;
    }
    if (right_side > left_side)
    return false;
    else
    return true;
    }
    if (palindromeTest == true)
    System.out.print ("palindrome.");
    else
    System.out.print ("not palindrome");
    }
    }

  2. #2
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    public class palindromette{
    public static void main (String[] args) {
    
    
    String user_input;
    Scanner scan = new Scanner(System.in);
    System.out.println ("Welcome to the Palindrome Application!");
    System.out.println ("This application will determine whether or not your input is a palindrome.");
    System.out.print ("Please enter a string:");
    user_input = scan.next();
    palindrome 
    boolean palindromeTest (String input) {
    int left_side = 0;
    int right_side = input.length() - 1;
    while ((input.charAt(right_side) == input.charAt(left_side)) && (right_side > left_side)) {
    right_side--; 
    left_side++;
    }
    if (right_side > left_side)
    return false;
    else
    return true;
    }
    if (palindromeTest == true)
    System.out.print ("palindrome.");
    else
    System.out.print ("not palindrome");
    }
    }

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    my code that has compile times errors on the method :
    What are you specific errors? Which line(s) throw them?

    Much luck.

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    For starters your method: palindromeTest(String input) should be a seperate method from main().
    Second, at line 13 you just say "palindrome" this will get an error. Also, when you say "palindromeTest == true" you need to say "palindromeTest(user_input) == true" becuase your method is expecting you to send it a String.
    My advice is to look at your compiler errors and fix them one at a time. Good Luck

  5. #5
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

Tags for this Thread

Posting Permissions

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