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

What is displayed by the following code? System .out. print(Hi, ABC, good\' .mat

ID: 3839248 • Letter: W

Question

What is displayed by the following code? System .out. print(Hi, ABC, good' .matches ("ABC ")+""); System .out. println ("H l, ABC. good" matches(" ABC"")); A. false false B. true false C. true true D. false true Which of the following statements will convert a string s into a double value d? A. d = Double.parseDouble(s); B. d = (new Double(s)).doubleValue(); C. d = Double.valueOf(s).doubleValue(); D. All of these. Analyze the following code.//Program 1 public class Test{public static void main(String[] args) {Object a 1 - new A(), Object a 2 = new A(); System out println(((A)al) equals((A)a2));} class A {int x public boolean equals (A a) {return this.x ==a x}}//Program 2 public class Test {public static void main(String[] args) {A a1 = newA(), A a2-new A(); System out println(al equals(a2));} class A {intx; public boolean equals(A a) {return this.x = =a.x;}} A. Program 1 displays true and Program 2 displays true B. Program 1 displays false and Program 2 displays true C. Program 1 displays true and Program 2 displays false

Explanation / Answer

1) Here we are using matches function which return true if your string matches with regular expression defined inside match function and false if not.
First system.out.println is trying to match "Hi,ABC, good" with "ABC" and here regular expression says a string exactly ABC hence false
Second system.out.println tries to match the string with regex .*ABC*. which means anything before ABC and anything after ABC hence our string matches with this regex so true

Output is false true

2) All of provided option will convert string to double.

3) Program 1 displays true and Program 2 displays true as in first we are first creating references but later we are cating them to be of type A and then for the objects equals method will work the same. The difference in Program 2 is just that we are directly creating object of A rather than references.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote