Question
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
-
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
-
5
-
-
Which of the following expressions is true if and only if NOT all three variables a, b, and c have the same value?
-
a != b && b != c
-
a != b || b != c
-
a >= b && b >= c && c >= a
-
a > b || b > c || a > c
-
!(a == b || b == c || a == c)
-
-
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);
-
Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"
-
1.5 is displayed
-
2.0 is displayed
-
2.1213203435596424 is displayed
-
ArithmeticException
-
-
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?
-
5 and 0
-
5 and 10
-
15 and 10
-
15 and 20
-
None of the above
-
-
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) -
123456
-
456123
-
456321
-
246135
-
IndexOutOfBoundsException
-
-
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; }
-
I and II only
-
I and III only
-
II and III only
-
All three are equivalent
-
All three are different
-
-
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;
-
I only
-
II only
-
I and II only
-
II and III only
-
I, II and III
-
-
Which of the following statements about developing a Java program is FALSE?
-
The main purpose of testing a Java program is to make sure it doesn't generate run-time exceptions.
-
Hello.class, a Java class file obtained by compiling Hello.java under a Windows operating system can be executed on a Mac computer.
-
The size of an int variable in Java is four bytes, the same under any operating system and computer model.
-
At run time, int values are represented in the computer memory in the binary number system.
-
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started