Consider the following Point2D class. public class Point2D { private double xCoord; private double yCoord; public Point2D(double x, double y) { xCoord = x; yCoord = y; } } Which of the following code segments, appearing in a class other than Point2D, will correctly create an instance of a Point2D object?
Blog
Consider the following code segment. int val = 48; int div…
Consider the following code segment. int val = 48; int div = 6; while ((val % 2 == 0) && div > 0) { if (val % div == 0) { System.out.print(val + ” “); } val /= 2; div–; } What is printed when the code segment is executed?
Consider the following code segment. int num = 1; while (nu…
Consider the following code segment. int num = 1; while (num < 5) { System.out.print("A"); num += 2; } What is printed as a result of executing the code segment?
Consider the following code segment. int k = 0; while (k < 1...
Consider the following code segment. int k = 0; while (k < 10) { System.out.print((k % 3) + " "); if ((k % 3) == 0) k = k + 2; else k++; } What is printed as a result of executing the code segment?
Consider the following method. public int sol(int lim)…
Consider the following method. public int sol(int lim) { int s = 0; for (int outer = 1; outer
Consider the following code segment. int val = 1; while (va…
Consider the following code segment. int val = 1; while (val
Consider the following method. public int mystery(int num) {…
Consider the following method. public int mystery(int num) { int x = num; while (x > 0) { if (x / 10 % 2 == 0) return x; x = x / 10; } return x; } What value is returned as a result of the call mystery(1034) ?
Consider the following code segment. int k = 1; while (k < 2...
Consider the following code segment. int k = 1; while (k < 20) { if ((k % 3) == 1) System.out.print(k + " "); k++; } What is printed as a result of executing this code segment?
Consider the following method, which is intended to count th…
Consider the following method, which is intended to count the number of times the letter “A” appears in the string str. public static int countA(String str) { int count = 0; while (str.length() > 0) { int pos = str.indexOf(“A”); if (pos >= 0) { count++; /* missing code */ } else { return count; } } return count; } Which of the following should be used to replace /* missing code */ so that method countA will work as intended?
Consider the following code segment. int j = 1; while (j <...
Consider the following code segment. int j = 1; while (j < 5) { int k = 1; while (k < 5) { System.out.println(k); k++; } j++; } Which of the following best explains the effect, if any, of changing the first line of code to int j = 0; ?