Code
int nElements = 10;
int array[] = new int[nElements];
for (int i=0; i < nElements; i++){
array[i] = (int)random(0,100);
}
println(array);
boolean bPalindrome = false;
for (int i=0; i <nElements; i++){
if (array [i] == array [nElements-1-i]){
bPalindrome = true;
}
}
if (bPalindrome){
println ("this array is a palindrome!");
} else {
println ("Sorry, this array is not a palindrome.");
}
...Quiz 052 (October 27): Testing Palindromes
Statement:
// Given the following code,
// write code to determine if the array
// is a palindrome (the same backwards and forwards).
//---------------------------
// DON'T TOUCH THIS CODE
int nElements = 10;
int array[] = new int[nElements];
for (int i=0; i < nElements; i++){
array[i] = (int)random(0,100);
}
println(array);
// Feel free to test your code with this array
// which is a guaranteed palindrome...
int arrayPal[] = {17, 31, 54, 99, 6, 6, 99, 54, 31, 17};
//---------------------------
// OK NOW YOUR CODE GOES HERE
// ...???
hide statement