Consider the following code segment, which is intended to display 0.5. int num1 = 5; int num2 = 10; double ans = num1 / num2; System.out.print(ans); Which of the following best describes the error, if any, in the code segment?
Blog
Consider the following code segment. int num = 1; int count…
Consider the following code segment. int num = 1; int count = 0; while (num
Consider the following code segment. int x = /* initial val…
Consider the following code segment. int x = /* initial value not shown */; int y = /* initial value not shown */; int z = x; z /= y; z += 2; Which of the following best describes the behavior of the code segment?
Consider the following code segment. double a = 7; int b =…
Consider the following code segment. double a = 7; int b = (int) (a / 2); double c = (double) b / 2; System.out.print(b); System.out.print(” “); System.out.print(c); What is printed as a result of executing the code segment?
A student has created a Song class. The class contains the f…
A student has created a Song class. The class contains the following variables. A String variable called artist to represent the artist name A String variable called title to represent the song title A String variable called album to represent the album title The object happyBirthday will be declared as type Song. Which of the following statements is true?
Consider the following code segment. int x = 4; int y = 6;…
Consider the following code segment. int x = 4; int y = 6; x -= y; y += x; Which of the following best describes the behavior of the code segment?
Consider the following code segment, which is intended to di…
Consider the following code segment, which is intended to display 6.0. double fact1 = 1 / 2; double fact2 = 3 * 4; double product = fact1 * fact2; System.out.println(product); Which of the following best describes the error, if any, in the code segment?
Consider the following code segment. double p = 10.6; doubl…
Consider the following code segment. double p = 10.6; double n = -0.2; System.out.print((int) (p + 0.5)); System.out.print((int) (n – 0.5)); What is printed as a result of executing the code segment?
Consider the following methods, which appear in the same cla…
Consider the following methods, which appear in the same class. public void slope(int x1, int y1, int x2, int y2) { int xChange = x2 – x1; int yChange = y2 – y1; printFraction(yChange, xChange); } public void printFraction(int numerator, int denominator) { System.out.print(numerator + “/” + denominator); } Assume that the method call slope(1, 2, 5, 10) appears in a method in the same class. What is printed as a result of the method call?
Consider the following Boolean expression in which the int v…
Consider the following Boolean expression in which the int variables x and y have been properly declared and initialized. (x 25) Which of the following values for x and y will result in the expression evaluating to true ?