1. Suppose that a and b are int values. Simplify the following expressions to a
ID: 3747747 • Letter: 1
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 < b) || !(a <= b))
1b. ( (a <= b) == false )
1c. (!(a > b) && !(a < 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 < 10; ++E ) {
// location 5
if( D < A ) {
int F = 1;
// location 6
}
// 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:
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 “”.
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:
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 doesn’t, don’t 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 tootExplanation / Answer
Solving first question as per chegg policy
1. Suppose that a and b are int values. Simplify the following expressions to a boolean expression involving only a single operator:
1a. ( (b < b) || !(a <= b))
b < b is always false so condition will always go to other part of 'or' (||). Hence it can be written as (!(a <= b))
Also if a <= b then negation of this is a > b
So overall this expression is reduced to (a > b)
1b. ( (a <= b) == false )
a <= b result in a boolean and equating it to false is same as taking a negation of it as negation of false is true and vice versa
so it is reduced to (!(a<= b)) which is same as what we saw above and hence it is reduced to (a > b)
1c. (!(a > b) && !(a < a))
a< a is always false and !(false) is true, so !(a<a) will be true
hence this is reduced to
(!(a > b)), negation of a > b is a <= b
so this expression is reduced to (a <= b)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.