Question: Java Question Question #3: To compare strings in Java you can't simply use the relational operators. You need to use methods of the String class:
Java Question

Question #3: To compare strings in Java you can't 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 equal to word2 b) word1 is lexicographically less than word2 c) word1 and word2 have the same three-letter prefix
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
