Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Step 7. Formal Assessment 1. The following code initializes the variables x and y: int x = 3; int y = 5; What is the data type of the value of the expression (x / y)? a. b. c. d. e. 2. number int double cast operator The following code initializes the variables x and y: int x = 3; double y = 1.0; What is the data type of the value of the expression (x % y)? a. b. c. d. e. 3. number int double cast operator After this code is executed, what is the value of z? double x = 2.5; double y = (2 * x); double z; z = (int)(x + (2 * y)); The value of z is a. b. c. d. e. 5.0 12 12.0 12.5 None of the above — an error occurs. Which is greater: a. 3 – 42 or (3 – 4)2 b. 3 x 7 + 9 or 3 x (7 + 9) c. 12 + 8/2 or (12 + 8)/2 d. 4 – 16/42 or 4 – (16/4)2 4. 5. the answer is (3 - 4)2 = 1 the answer is 3 x (7 + 9) the answer is 12 + 8/2 the answer is 4 – 16/42 After this code is executed, what is the value of z? int x = 2.5; int y = (2 * x); int z = y / 2; The value of z is a. b. c. d. e. 6. 2 2.5 3 5 None of the above — an error occurs. What is the value of ((int)-5.2 + 1)? a. b. c. d. -4 -5 -7 NaN e. None of the above — an error occurs. 7. What is the remainder of 376 / 30? The answer is 16 8. Which of these expressions evaluates to 1.0? a. b. c. d. e. 3/2 (double)3 / (double)2 (double)(3 / 2) 3 / (double)2 (double)3 / 2 9. After this code is executed, what is the value of p? int r = 5; r++; int p = r; r--; The value of p is a. b. c. d. e. 4 5 6 7 None of the above Suppose that the variables a, b and c are initialized as follows: 10. int a = 10; int b = 14; int c = 25; Which of these expressions evaluates to the arithmetic mean of a, b and c? a. b. c. d. e. 11. (double)a + (double)b + (double)c / 3.0 (a + b + c) / 3 (a + b + c) / 3.0 (double)((a + b + c) / 3) None of the above. After this code is executed, what is the value of x? double x = 4.5; double y = 5.4; int z = 5; x += (int)x + (int)y / z; The value of x is a. b. c. d. e. 5 5.5 9 9.5 None of the above. 12. A traffic light cycles through three different colors; green to yellow to red. If the light is green now, what color will it be after 976 changes? Yellow. When you divide 976 by 3 the remainder is 1. Therefore the light is one color past green. 13. Make a program that prompts the user the current temperature in Fahrenheit degree and convert to Celsius. Then write a second program for Celsius and convert into Fahrenheit. The formula from Fahrenheit to Celsius is Tc = (5/9)*(Tf-32) and from Celsius to Fahrenheit is Tf = (9/5)*Tc+32. // simple program that converts from Fahrenheit to Celsius import java.util.Scanner; public class FromFtoC { public static void main(String[] args) { double degreesF, degreesC; Scanner console = new Scanner(System.in); System.out.println("What's current Fahrenheit temperature? "); degreesF = console.nextDouble(); degreesC = 5.0/9.0 * (degreesF - 32); System.out.print("That corresponds to " + degreesC + "in Celsius"); } } // simple program that converts from Fahrenheit to Celsius import java.util.Scanner; public class FromCtoF { public static void main(String[] args) { double degreesF, degreesC; Scanner console = new Scanner(System.in); System.out.println("What's current Celsius temperature? "); degreesC = console.nextDouble(); degreesF = (9.0/5.0) * degreesC + 32; System.out.print("That corresponds to " + degreesF + " in Fahrenheit"); } }