Question: Question #1 (1pt): Assume x and y are integers. Using relational and logical operators, formulate the following 5 conditions in Java: For Example: x is
Question #1 (1pt): Assume x and y are integers. Using relational and logical operators, formulate the following 5 conditions in Java: For Example: x is positive Answer: x > 0
a) x is zero or positive
b) x is no more than 10
c) x is greater than 10 d) x and y are both zero
e) x is odd
Question #2 (2 pts): Using relational and logical operators, formulate the following 2 conditions in Java, given the variables day and month of type int. For Example: The date is in the second quarter of the year. Answer: 4 <= month && month <= 6
a) The date is the first day of February
b) The date is after April 15
Question #3 (2 pts): To compare strings in Java you cant simply use the relational operators. You need to use methods of the String class: equals(), compareTo(), and substring(). Assume the following code: String word1 = "catalog"; String word2 = "cat"; Write the following 3 conditions in Java: For Example: word1 is lexicographically greater than "aaa" Answer: word1.compareTo("aaa") > 0
a) word1 is lexicographically not equal to word2
b) word1 is lexicographically greater than word2
c) word1 and word2 have the same two-letter prefix
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
