Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

he expression \"hello\".equals(\"hello\") evaluates to: 10 points QUESTION 2 The

ID: 3752394 • Letter: H

Question

he expression "hello".equals("hello")  evaluates to:

10 points   

QUESTION 2

The expression  "hello".compareTo("hello") evaluates to:

10 points   

QUESTION 3

The expression  "hello".compareTo("hello")<0 evaluates to:

10 points   

QUESTION 4

What will this expression evaluate to: "ascending".compareTo("curious")

10 points   

QUESTION 5

Assume that word is a String variable with data from the user given as follows:  
String word = kb.nextLine();
Mark all of the boolean expressions below that evaluate to true
if the user entered the text    Monday.

"word".compareTo("Monday")== 0

"monday".compareTo(word) == 0

"Monday".compareTo(word) == 0

word.compareTo("Monday")== 0

word.compareTo("MONDAY")== 0

"Monday".compareTo("word")== 0

12 points   

QUESTION 6

String s1 = kb.nextLine();

s1 = "rescue";

(s1.compareTo("rescue") < 0) && ( "rescue".compareTo(s1) > 0 )

evaluates to

true

false

Neither. It crashes.

It depends on the user input.

10 points   

QUESTION 7

In the expression:  day.compareTo("monday") == 0
The method compareTo is called on the object day.

True

False

8 points   

QUESTION 8

Call the equals method on the word object to check if it equals Tuesday . Do not put extra spaces. You MUST use the equals method, not the compareTo and you must call it on the wordobject (not viceversa). (There is only one way to do this.)

10 points   

QUESTION 9

Write the boolean expression that evaluates to true if variable word has value either  Tuesday or  Thursday . Do not put extra empty spaces. You MUST use the equals method, and call it on the word object. You must put parenthesis around the individual questions used in the expression, e.g. :  (x<8)&&(x>3)  

10 points   

QUESTION 10

// Assume variables data1 and data2 have already been declared.

data1 = kb.nextLine(); // assume the user enters 8

data2 = kb.nextLine(); // Assume the user enters 201

Is the statement below correct?

The expression data1.compareTo(data2)<0   evaluates to true.


Yes
No

"word".compareTo("Monday")== 0

"monday".compareTo(word) == 0

"Monday".compareTo(word) == 0

word.compareTo("Monday")== 0

word.compareTo("MONDAY")== 0

"Monday".compareTo("word")== 0

Explanation / Answer

NOTE: According to the chegg policy when there are more than 4 questions are given we have to answer only first 4 questions but here I am giving you the 6 answers.

ANSWER 1: The expression "hello".equals("hello") will return true because in java we use .equals() method to content comparision.

ANSWER 2: The expression  "hello".compareTo("hello") will return 0 because we know that this method can return three values:

greater than 0: Object is greater than the argument object

So here it will return 0 because both are same.

ANSWER 3: Here expression "hello".compareTo("hello")<0 will give ypu the false because "hello".compareTo("hello") will return the 0 and 0<0 is false so it will give you the false.

ANSWER 4: Here in the expression

"ascending".compareTo("curious")

first string is lexicographically greater than the second string so it will return you less than 0 number.

ANSWER 5: here below are the expessions which will retun true as :

word.compareTo("Monday")== 0 because both string Monday are lexicographically equal so compareTo method will return 0 and it is comparing with 0 which will give you the true. and expression "Monday".compareTo(word) == 0 also give you true.

ANSWER 6: It will return false because both expressions in && operation will give you the false.