Question: 1. Suppose that a and b are int values. Simplify the following expressions to a boolean expression involving only a single operator: 1a. ( (b
1. Suppose that a and b are int values. Simplify the following expressions to a boolean expression involving only a single operator:
1a. ( (b
1b. ( (a
1c. (!(a > b) && !(a
2. In the following program, for each name A, B, C, D, E, F, G of a variable or method, state the locations (1 to 9) which are in the scope of the variable. For example, for variable A you would write 1 - 9 or all.
public class ScopeTest { public static int A = 2;
// location 1
public static void B( int C ) { // location 2 }
public static void main (String[] argv) { // location 3
int D = 2;
// location 4
for( int E = 0; E
if( D
} // location 7
} // location 8 }
// location 9 public static int G = 2; }
3. Read in the string and call a function named isPalindrome, which you will write, to determine if the string passed is in fact a palindrome.
Write the method isPalindrom which should have the following signature:
public static boolean isPalindrome( String s ) { boolean isPal = false; // assume that it is not // code to determine if the string s is a palindrome // If the default (as above) assumes the string is not a palindrome, // the logic here should determine if it is and reassign the return // variable isPal appropriately, or vice verse. return( isPal ); } Encode the logic of the method:
Convert the string s to all lower case.
Remove any character from the string which is neither a letter nor a digit. Hint: use replace(....) to replace any non-letter non-digit by the empty String .
Check if the string s is a palindrome by checking to see if each letter is the same as the letter in its mirror image position; for example Taco Cat and Toot! are palindromes:
but honor is not.
NOTE: There are multiple ways that you can solve this problem, but you are to follow the steps outlined. For example, you may NOT form the solution to the problem by converting the String to a char array first OR reverse the String and then compare if they are equal.
Test your code on at least the following palindromes:
A man, a plan, a canal, Panama! Go hang a salami, I'm a lasagna hog! Campus Motto: Bottoms up, Mac! 7/1/17 // A palindrome date! Are we not pure "No sir!" Panama's moody Noriega brags. It is garbage! Irony dooms a man; a prisoner up to new era.
Note that the last quote may cause a problem because there are various kinds of smart quotes which are different from the simple ASCII double quotes; if all the others work and this one doesnt, dont worry about it!
Also test your code on a non-palindrome example such as the word palindrome itself, or this sentence!
Important guidelines:
You may not use recursion to solve this problem.
Your program is to execute as specified. It is to print out Palindrome! or Not a palindrome! depending on your answer. Here is an example of what your program should do:
tacocat toot
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
