Wednesday, November 2, 2011

palindrome

  • Question:-palindrome?
    what is the longest palindrome you can come up with? I once heard a sentance that was one, but I forgot it...have at it!

    Answer:-Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol, Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny, Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, Eva, Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, Cecil, Aaron, Flora, Tina, Arden, Noel, and Ellen sinned.”
  • Question:-Palindrome??????????????
    What is a single word obscene palidrome? Like a curse word or an offensive word?

    HURRY ITS FOR MY SENIOR SCAVENGER HUNT NOW!!!

    Answer:-boob?
  • Question:-How to write a palindrome program in Java?
    Create a Palindrome application that prompts the user for a string then displays a message indicating whether or not the string is a palindrome. A palindrome is a word or phrase that is spelled the same backwards and forwards. For example, “mom” is a palindrome, as well as “kayak” and “Never odd or even”.

    Answer:-Here ya go be sure to best answer


    public class Palindrome {
    private String pal;

    public Palindrome(String initPal) {
    pal = initPal.toUpperCase();
    }

    public boolean isPalindrome() {

    if (pal.length() <= 1) {
    // String has only one character so it
    // is a Palindrome by definition.
    return true;// BASE CASE.
    }

    // Get the first and last characters of the String.
    char first = pal.charAt(0);
    char last = pal.charAt(pal.length()-1);

    if (Character.isLetter(first) &&
    Character.isLetter(last)) {
    // The first and last characters are both letters..

    if (first != last) {
    // The first and last letters are different
    // so the string is not a Palindrome.
    return false; // BASE CASE.
    }
    else {
    // The first and last characters are both letters,
    // and they are both the same. So, the string is
    // a palindrome if the substring created by dropping
    // the first and last characters is a palindrome.
    Palindrome sub = new Palindrome(
    pal.substring(1,pal.length()-1));
    return sub.isPalindrome(); // RECURSIVE CASE.
    }
    }
    else if (!Character.isLetter(first)) {
    // The first character in the string is not a letter.
    // So the string is a palindrome if the substring created
    // by dropping the first character is a palindrome.
    Palindrome sub = new Palindrome(pal.substring(1));
    return sub.isPalindrome(); // RECURSIVE CASE.
    }
    else {
    // The last character in the string is not a letter.
    // So the string is a palindrome if the substring created
    // by dropping the last character is a palindrome.
    Palindrome sub = new Palindrome(
    pal.substring(0,pal.length()-1));
    return sub.isPalindrome(); // RECURSIVE CASE.
    }
    }

    public static void main(String[] args) {
    Palindrome p1 = new Palindrome("Madam, I'm Adam.");
    System.out.println(p1.isPalindrome());
    Palindrome p2 = new Palindrome("Nope!");
    System.out.println(p2.isPalindrome());
    Palindrome p3 = new Palindrome("dad");
    System.out.println(p3.isPalindrome());
    Palindrome p4 = new Palindrome("Go hang a salami, I'm a lasagna hog.");
    System.out.println(p4.isPalindrome());
    }
    }
  • Question:-What is the first palindrome greater than 10000 and divisible by 3?
    What is the first palindrome greater than 10000 and divisible by 3? Please help!

    Answer:-10101.

    Any number less than this (and greater than 10000) will not be a palindrome. Moreover, 10101 / 3 = 3367.

    I hope that helps!
  • Question:-What is the longest palindrome you can think of?
    I saw a person ask what a palindrome is. What is the longest palindrome? Or, longest one (most letters) that you can think of?

    Answer:-The longest single English word in common usage which is a palindrome is REDIVIDER, although the contrived chemical term DETARTRATED is two letters longer. In Finnish there is a 25-letter palindromic word: SOLUTOMAATTIMITTAAMOTULOS which means the result from a measurement laboratory for tomatoes, although technically it is a compound of four words. There is also the equally long SAIPPUAKUPPINIPPUKAUPPIAS which means soap cup trader.
  • Question:-How can I write a java program to check a palindrome of a string?
    My Lecturer asked me to write a java program to check a palindrome of a string? Could you kindly show me how to maybe be give an example.

    Answer:-boolean isPalindrome(String s){
    for (itn i=0; i < string.length()/2; i++)
    if (s.charAt(i) != s.charAt(string.length()-i))
    return false;
    return true;
    }

    ... you might want to check the end points .. but its the general idea

    this is a palindrome

    asdffdsa
  • Question:-What's the longest palindrome made without using a palindrome-generating program?
    I'm trying to make the longest palindrome that doesn't make use of a generator. How long is the longest one that doesn't use a generator?

    Answer:-Finnish has the longest single-word palindromes, with two entries: “saippuakivikauppias,” which means “soap stone dealer”; and “solutomaattimittaamotulos,” which means “the result from a measurement laboratory for tomatoes.” Depending on who you ask, “tattarrattat,” “kinnikinnik,” or “detartrated” is the longest single-word palindrome in English, though some would say these words are not really part of the English language, since they are contrived or almost never used.
  • Question:-3digit postive integers.What is the probability that any thee-digit palindrome is also a multiple of eleven?
    You are given a special set of numbers that contains all three-digit positive integers that are palindromes. What is the probability that any thee-digit palindrome is also a multiple of eleven?

    Answer:-Since the numbers are in a form xyx, There are nine possible digits for x (1-9) and ten for y (0-9). So off the bat, there are only 90 numbers in this set.

    101x + 10y = 11z

    For any given x, only one value of y at most is going to produce a multiple of 11. That's because whichever value it is, the next one up will be y+11, and y only goes from 0 to 9.

    At x=1, the value of y has to be 2, for the number 121.
    At x=2, y=4, for 242.
    x=3, y=6: 363
    x=4, y=8: 484

    As you can see there's a pattern where y=2x. If you add or subtract 11 to y you can still have a multiple of 11.

    At x=5, y=10, and since y=10 is not an acceptable value, there is no multiple of 11 where x=5.

    At x=6, y=12. y=12 is not valid but you can subtract 11 to get it back into range. x=6, y=1: 616. And 616 = 11 × 56.

    x=7, y=14 -> 3: 737
    x=8, y=16 -> 5: 858
    x=9, y=18 -> 7: 979

    All nine values of x except for 5 had a single palindrome divisible by 11. So out of 90 palindromes, 8 were divisible by 11.

    8/90 = 4/45
  • Question:-How to write a class Palindrome() to identify palindromes from a set of strings?
    Palindrome is a word that reads the same forward and backward. Needs to accept the strings and confirm or deny its palindrome.

    Answer:-yeah, you want to read in the words (strings)
    eg string a = "hannah"
    string b = "doctor"
    string c = "flower"

    now reverse each string
    string a2 = "hannah"
    string b2 = "rotcod"
    string c2 = "rewolf"

    now create an argument that says
    if a = a2,
    give output as "this word is a palindrome"

    else
    give output as "this word is not a palindrome"

    you could also include something in there which tells the program to ignore whether characters in the string are upper- or lower-case, so that it doesn't tell you that "Hannah" is different to "hannaH"

    hope you can form a program from this in whatever language you're using
  • Question:-How do I can write a program "Palindrome"to testing if a line of text (read from the keyboard) is apalindrome?
    A palindrome is a text consisting of the same sequence of characters read
    backwards, as if read from the front. Ignore all characters that are not letters, and consider
    an upper case letter to be equal to the corresponding lower case letter. Examples of
    palindromes:
    "Anna" "x" "Ff" "A1 n2%}=3N{[a]" "Was it a rat I saw?”
    Sorry! In Java.

    Answer:-in java.

    import java.util.*;
    public class Palindrome {

    public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    isPalindrome(sc.nextLine());
    }

    public static void isPalindrome(String s){
    s=s.replaceAll("[^a-zA-Z]","");
    s=s.toLowerCase();
    char[] orgStr =s.toCharArray();
    String revStr="";
    for(int i=orgStr.length-1;i>=0;i--){
    revStr+=orgStr[i];//System.out.println(orgStr[i]);
    }
    if(s.equals(revStr)){System.out.println("its a PALINDROME");}
    else {System.out.println("its not a PALINDROME");}
    }
    }

No comments:

Post a Comment