**1. What is the output of the following code?**

```java
double x = -97.6;
System.out.println(Math.abs(x));
```

A) 97.6
B) -96
C) -97.6
D) 98
E) -98

---

**2. Which of the following methods has the same signature as the method with return type `String`, name `myMethod`, and parameter list `String s, int i`?**

A) Return type: `String`, name: `myMethod`, parameter list: `double d, int i`
B) Return type: `double`, name: `myMethod`, parameter list: `String s, int i`
C) Return type: `String`, name: `myMethod`, parameter list: `String s`
D) Return type: `String`, name: `myMethod`, parameter list: `int i, String s`

---

**3. What is the output of the following code segment?**

```java
Integer a = new Integer(12);
Integer b = new Integer(22);
System.out.println(a.compareTo(b));
```

A) false
B) -1
C) 0
D) 1

---

**4. Which of the following describes the return type and parameters of the `Scanner` method `nextLine`?**

A) Return type: `String`. Parameters: none
B) Return type: `void`. Parameters: one `String` parameter
C) Return type: `void`. Parameters: none
D) Return type: `String`. Parameters: one `String` parameter

---

**5. Which of the following correctly gives random numbers between -10 and 10 inclusive?**

A) `int n = (int) (Math.random() * 10) - 20`
B) `int n = (int) (Math.random() * 10) - 21`
C) `int n = (int) (Math.random() * 11) - 20`
D) `int n = (int) (Math.random() * 20) - 10`
E) `int n = (int) (Math.random() * 21) - 10`

Answer :

Final answer:

The code snippet in question outputs the absolute value of -97.6 which is 97.6. A method with the signature String myMethod(String s, int i) is correctly represented by the option with a return type of double, and parameters String s, int i. The compareTo method outputs -1 when comparing 12 to 22, the Scanner nextLine method has a return type of string and no parameters. The correct code to generate random numbers between -10 and 10 is int n = (int) (Math.random() * 20) - 10.

Explanation:

The output of the code double x = -97.6; System.out.println(Math.abs(x)); will be A) 97.6 because the Math.abs method returns the absolute value of a given double value.

Among the described methods, the method that has the same signature as a method with return type of String, the name myMethod and a parameter list of String s, int i is B) return type: double, name: myMethod, parameter list: String s, int i

In the code segment Integer a = new Integer(12); Integer b = new Integer(22); System.out.println(a.compareTo (b));, the output will be B) -1. This is because the compareTo method compares two Integer values numerically and returns -1 if the first value is less than the second.

The method nextLine of the Scanner class has return type and parameters as described in option A) Return type: String. Parameters: none.

To generate random numbers between -10 and 10 inclusive, the correct code is D) int n = (int) (Math.random() * 20) - 10. This will produce a random number in the interval [-10,10].

Learn more about Java Programming here:

https://brainly.com/question/2266606

#SPJ11

Other Questions