Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is printed as a result of executing the following statements? double x = 2.5, y = 1.99; System.out.println((int)(x/y) + (int)(x*y)); 0 3 4 4.0

  1. What is printed as a result of executing the following statements?

    double x = 2.5, y = 1.99; System.out.println((int)(x/y) + (int)(x*y));

    1. 0

    2. 3

    3. 4

    4. 4.0

    5. 5

  2. Which of the following expressions is true if and only if NOT all three variables a, b, and c have the same value?

    1. a != b && b != c

    2. a != b || b != c

    3. a >= b && b >= c && c >= a

    4. a > b || b > c || a > c

    5. !(a == b || b == c || a == c)

  3. What is the result when the following code segment is compiled and executed?

    int m = 4, n = 5; double d = Math.sqrt((m + n)/2); System.out.println(d);

    1. Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"

    2. 1.5 is displayed

    3. 2.0 is displayed

    4. 2.1213203435596424 is displayed

    5. ArithmeticException

  4. For which of the following pairs of values a and b does the expression

    (a > 20 && a < b) || (a > 10 && a > b)

    evaluate to true?

    1. 5 and 0

    2. 5 and 10

    3. 15 and 10

    4. 15 and 20

    5. None of the above

  1. What is printed as a result of executing the following code segment?

    List lst = new ArrayList(); for (int k = 1; k <= 6; k++) lst.add(new Integer(k)); for (int k = 0; k < 3; k++) { Integer i = lst.remove(k); lst.add(i); } for (Integer i : lst) System.out.print(i)

    1. 123456

    2. 456123

    3. 456321

    4. 246135

    5. IndexOutOfBoundsException

  2. Which of the following methods are equivalent (always return the same value for the same values of input parameters)?

    public boolean fun(int a, int b, int c) { if (a >= b) if (b >= c) return true; else return false; else return false; }

    public boolean fun(int a, int b, int c) { if (a >= b && b >= c) return true; else return false; }

    public boolean fun(int a, int b, int c) { return a >= b || b >= c; }

    1. I and II only

    2. I and III only

    3. II and III only

    4. All three are equivalent

    5. All three are different

  3. Consider the following class.

    public class Matrix { private int[][] m; /** Initializes m to a square n by n array with all * the elements on the diagonal m[k][k] equal to 0 and * all other elements equal to 1 */ public Matrix(int n) { m = new int[n][n]; < missing code > } < other constructors and methods not shown > }

    Which of the following could replace < missing code> in Matrix's constructor, so that it compiles with no errors and works as specified?

    for (int r = 0; r < n; r++) for (int c = 0; c < n; c++) m[r][c] = 1; for (int k = 0; k < n; k++) m[k][k] = 0;

    for (int k = 0; k < n; k++) m[k][k] = 0; for (int r = 0; r < n; r++) for (int c = 0; c < n; c++) if (r != c) m[r][c] = 1;

    for (int c = 0; c < n; c++) for (int r = 0; r < n; r++) if (r == c) m[r][c] = 0; else m[r][c] = 1;

    1. I only

    2. II only

    3. I and II only

    4. II and III only

    5. I, II and III

  4. Which of the following statements about developing a Java program is FALSE?

    1. The main purpose of testing a Java program is to make sure it doesn't generate run-time exceptions.

    2. Hello.class, a Java class file obtained by compiling Hello.java under a Windows operating system can be executed on a Mac computer.

    3. The size of an int variable in Java is four bytes, the same under any operating system and computer model.

    4. At run time, int values are represented in the computer memory in the binary number system.

    5. Division of an integer value by zero in a Java program will cause a run-time ArithmeticException.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Discuss how organizations can benefit from XBRL.

Answered: 1 week ago

Question

Presentations Approaches to Conveying Information

Answered: 1 week ago