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

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.

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!

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
Palindrome
Palindrome  program to verify palindrome
palindrome
palindrome  write a program to print palindrome numbers between 500 to 700
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  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 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
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 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
java palindrome
java palindrome  sir i need java program to print 1)integer palindrome 2)string palindrome
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
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
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
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
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
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
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!"
palindrome - Java Beginners