Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners palindrome array problem

Have Programming Question? Ask it here!
 
 
 


Gabriel Dos Santos
palindrome array problem
2 Answer(s)      a year and 6 months ago
Posted in : Java Beginners


I'm having trouble figuring this assignment out. Can someone please help me?

Generate (write the code) and save in an array Palidrome[250][5] all the 5 letter words using {a, b, c}

Write the code and show the execution for:

a.) Count the number of palindromes in this set.

b.) Print out all the palindromes where a letter appears more than twice.

   Examples a a b a a ;  b b b b b;  c a c a c;   a b b b a   etc.

c.) Print out all the palindromes where a letter appears no more than twice.

Examples a b c b a; a c b c a etc.


Advertisement
View Answers

October 10, 2012 at 12:57 PM


Here is a code that displays all the 5 letter words using {a, b, c}and display the palindromes from them.

public class GeneratePalindromes{
    static boolean isPalindrome(String s){
        int left = 0;
        int right = s.length() - 1;
        while (left < right){
        if (s.charAt(left) != s.charAt(right))
        return false;
        left++;
        right--;
        }
        return true;
    }
    public static void main(String[] args){
        char[] chars = "abc".toCharArray();
        int len = 5;
        System.out.println("Display all the words: ");
        iterate(chars, len, new char[len], 0);
        System.out.println("Display all the palindromes: ");
        checkPalin(chars, len, new char[len], 0);
    }
    public static void iterate(char[] chars, int len, char[] build, int pos) {
            if (pos == len) {
            String word = new String(build);
            System.out.println(word);
            return;
            }
           for(int i = 0; i < chars.length; i++) {
            build[pos] = chars[i];
            iterate(chars, len, build, pos + 1);
        }
    }
     public static void checkPalin(char[] chars, int len, char[] build, int pos) {
            if(pos == len) {
            String word = new String(build);
            if(isPalindrome(word)){
            System.out.println(word);
            }
            return;
        }
           for(int i = 0; i < chars.length; i++) {
            build[pos] = chars[i];
            checkPalin(chars, len, build, pos + 1);
        }
    }
}


October 10, 2012 at 7:22 PM


Thank you so much!



Related Tutorials/Questions & Answers:
palindrome array problem
palindrome array problem  I'm having trouble figuring this assignment out. Can someone please help me? Generate (write the code) and save in an array Palidrome[250][5] all the 5 letter words using {a, b, c} Write the code
The Array Palindrome Number in Java
The Array Palindrome Number in Java   .... In this section you will read how to uses palindrome one dimensional array program. The array palindrome number arrange the array number. This session
Advertisements
Palindrome
Palindrome  program to verify palindrome
palindrome
palindrome  write a program to print palindrome numbers between 500 to 700
palindrome
palindrome  program to find the given string is palindrome...]; } if(st.equalsIgnoreCase(reversedSt)){ System.out.println("String is palindrome"); } else{ System.out.println("String is not palindrome
palindrome
palindrome  how to write in string of palindrome?   import... is palindrome"); } else{ System.out.println("String is not palindrome
palindrome
palindrome  how to write in string of palindrome   import... is palindrome"); } else{ System.out.println("String is not palindrome
PALINDROME
PALINDROME  how to find palindrome of a number WITHOUT using a string... == reversedNumber){ System.out.print("Number is palindrome!"); } else{ System.out.println("Number is not palindrome!"); } } catch(Exception e){ System.out.println(e
array problem
array problem  An integer array a has 19 elements. What is the value of the middle element after the following codes is executed? int i, j,n=19; for (i=0; i for(i=0, j=n-1; i<=j; i++, j--) a[(i+j)/1] -= (a[i]+a[j])/2
Problem in Array
Problem in Array  Hi, Can you help me with this problem? Run a program that check if the input string contains equal number of A's and B's. Hoping for your answer.Thank you.   Here is an example that check
Array /string based problem....
Array /string based problem....  thanx to help me.but again a problem... solve this problem also as soon as possible..... import java.util.*; public class... or char"); char[] array = new char[5]; for(int i=0;i<5;i++){ char ch
string array based problem
string array based problem  R/sir, firstly thanks... sorted value: 11 12 13 3 this is the problem here...... import java.util.*; public... string: "); String[] array = new String[5]; for(int i=0;i<5;i++){ array[i
problem in array if condtion
problem in array if condtion  sir i have prblem in js...i have array... = new Array(); arr[0] = new Array("-select-"); arr[1] = new Array("Maharashtra","Karnataka","Kerela","Rajashthan"); arr[2] = new Array("Texas","New York","Florida
java array problem
java array problem  suppose i have an array a[] at a[0] i have value 5,7 the thing is that i want to assign the value of array a[0]=5,7 to two variable let it be j,k that is j=5 and k=7 plz help regards
array and string based problem
array and string based problem  this program is accepting only..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1; int k = array[j]; while ((i>= 0) && (array[i] > k)){ array[i
array and string based problem
array and string based problem  this program is accepting only..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1; int k = array[j]; while ((i>= 0) && (array[i] > k)){ array[i
array and string based problem
array and string based problem  this program is accepting only..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1; int k = array[j]; while ((i>= 0) && (array[i] > k)){ array[i
Array problem - JSP-Servlet
Array problem  Respected Sir/Madam, I am having a pop up window in which the database values are available.. Its in the format of: One..... Bur my problem is that if the pop up window contains only 1 record
palindrome - Java Beginners
palindrome  use array to write a program that checks if a word is palindrome. A word is said to be palindrome if it reads the same forward... noon is a palindrome. Enter a word: moon moon is not a palindrome.  Hi
java palindrome
java palindrome  sir i need java program to print 1)integer palindrome 2)string palindrome
array problem java - Java Beginners
array problem java  PLS HELP ME NOW I NEED YOU RESPONSE IMMDEATLETLY HOPE ITS OK... 1.) Consider the method headings: void funcOne(int[] alpha..., respectively. another problem.,, 2.)Suppose list is an array of five
prime palindrome
prime palindrome  Hi I want to write a program in pascal that ask a user to input a number, the program then list all the prime number that are palindrome below the number entered. thks
prime palindrome
prime palindrome  Hi I want to write a program that ask a user to input a number, the program then list all the prime numbers that are palindrome below the number entered. In pascal language Thanks
complete the code (palindrome) - Java Beginners
complete the code (palindrome)  Write a program that checks if a word is palindrome. A word is said to be palindrome if it reads the same forward...: noon noon is a palindrome. Enter a word: moon moon is not a palindrome
To check a palindrome number?
To check a palindrome number?  program to check a number is palindrome or not using recursion?(wihout converting to string
palindrome - Java Beginners
palindrome  Write a program to find whether a given string is a palindrome or not  Hi Friend, Try the following code: import...) { String str="madam"; Stack s= new Stack(); int i,count=0; char array
Exercise - Palindrome
Java: Exercise - Palindrome Problem Write a method which returns true if the string parameter is a palindrome. A palindrome is any "word" which... return false if the argument is not a palindrome. Signature
To find palindrome no in a file - Java Beginners
To find palindrome no in a file  hi all i am having a problem...I wanted to write one java program where i have to count the no of palindrome in a file. I tried it with my own but not able to get result.pls help me out  
palindrome - Java Beginners
palindrome  example of java program if it is a palindrome or not palindrome   Hi friend, Example to check the number is a palindrome...){ System.out.print("Number is palindrome!"); } else
palindrome - Java Beginners
palindrome  determines whether or not it is a palindrome. if the number is not five... == digit4)){ System.out.print("Number is palindrome!"); } else{ System.out.println("Number is not palindrome!"); } } catch(Exception e  
palindrome - Java Beginners
palindrome in java code  I need an example of palindrome in Java ...;& (digit2 == digit4)){ System.out.print("Number is palindrome!"); } else{ System.out.println("Number is not palindrome!"
Java: Example - Palindrome test
Java: Example - Palindrome test //========================================================= isPalindrome // This method returns 'true' if the parameter // is a palindrome, a word that is spelled the // same both
palindrome - Java Beginners
palindrome  import java.io.*; class Palindrome { System.out.println("Enter a word:"); BufferedReader br=new BufferedReader(new InputReaderStream(System.in)); String word; word=br.readLine(); public static void main
Facing Problem to insert Multiple Array values in database - JSP-Servlet
Facing Problem to insert Multiple Array values in database  Hai... facing the problem while inserting the data in database. iam using the MsAccess... Manoj   Hi friend, You Have Problem in Data Table and check
Java Program to check Palindrome
Java Program to check Palindrome In this section, you will learn about palindrome in java and how to check any number that is palindrome or not. First of all what is palindrome number?, this is the number that the original number
Palindrome Number Example in Java
Palindrome Number Example in Java    ... the palindrome number and how to determine any number is palindrome or not. First of all we are going to read about the palindrome number.  This is the number
Check whether the number is palindrome or not
Check whether the number is palindrome or not A palindrome is a word, phrase... is palindrome or not. You can check it in various ways but the simplest method...; } if (n == reversedNumber) { System.out.print("Number is palindrome
Finding all palindrome prime numbers - Java Beginners
Finding all palindrome prime numbers  How do i write a program to Find all palindrome prime numbers between two integers supplied as input (start and end points are excluded
Palindrome program in Java
Palindrome program in Java helps programmers to determine if a number or string is palindrome or not. palindrome number or string remains unchanged when.... The logic used in Java program behind finding a number or sting is palindrome
how to write a function to print for finding the longest palindrome in the given string
how to write a function to print for finding the longest palindrome in the given string  how to write a function to print for finding the longest palindrome in the given string
Program to display palindrome numbers between some range
Program to display palindrome numbers between some range  Hi!I want a java program to display palindrome numbers between 100 to 1000.can you please explain me the logic with an example   import java.util.*; public
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend...(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
 

 

 

DMCA.com