Question 41 Which of the following is NOT a valid assignment statement? A. x = 55; B. 55 = x; C. x += 3; D. x = 56 + y;
Question 42 What is the result of 45 / 4? A. 11.25 B. 10 C. 12 D. 11 Question
43 What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0"); else System.out.println("x equals 0"); A. x is greater than 0 B. x is less than 0 C. x equals 0 D. None
Question 44 What is the exact output of the following code? double area = 3.5; System.out.print("area"); System.out.print(area); A. area3.5 B. area 3.5 C. 3.5 3.5 D. 3.53.5
Question 45 What does System.out.println("Welcome" + 1 + 1 * 2); print? A. Welcome3 B. Welcome11*2 C. Welcome12 D. Welcome4
Question 46 Which of the following is the best for generating random integer 0 or 1? A. (int)(Math.random() + 0.5) B. (int)Math.random() + 1 C. (int)Math.random() D. (int)(Math.random() + 0.2) Question 47 What is the printout of the following code: double x = 10.1; int y = (int)x; System.out.println("x is " + x + " and y is " + y); A. x is 10.0 and y is 10.0 B. x is 10.1 and y is 10.0 C. x is 10.1 and y is 10 D. x is 10 and y is 10
Question 48 You should fill in the blank in the following code with ________. public class Test { public static void main(String[] args) { System.out.print("The grade is "); printGrade(78.5); System.out.print("The grade is "); printGrade(59.5); } public static __________ printGrade(double score) { if (score >= 90.0) System.out.println('A'); else if (score >= 80.0) System.out.println('B'); else if (score >= 70.0) System.out.println('C'); else if (score >= 60.0) System.out.println('D'); els System.out.println('F'); } } A. void B. boolean C. double D. char Question 49 The ________ method parses a string s to an int value. A. Integer.parseInteger(s); B. Integer.parseInt(s); C. integer.parseInteger(s); D. integer.parseInt(s);
Question 50 Suppose x = 1, y = -1, and z = 1. What is the printout of the following code? if (x < 0) if (y < 0) System.out. println("x < 0 and y < 0"); else if (z < 0) System.out. println("x < 0 and z < 0"); else System.out. println("x < 0 and z > 0"); A. x > 0 and y > 0; B. x < 0 and z > 0; C. x < 0 and z < 0; D. no printout.
41. B. 55 = x; 42. A. 11 43. C. x equals 0 44. A. area3.5 45. C. Welcome12 46. A. (int)(Math.random() + 0.5) 47. C. x is 10.1 and y is 10 48. A. void 49. B. Integer.parseInt(s); 50. D. no printout.

Question 41 Which of the following is NOT a valid assignment statement? A. x = 55;...
With a Scanner object created as follows, what method do you use to read an int value? Scanner input = new Scanner(System.in); A. input.int(); B. input.nextInt(); C. input.integer(); D. input.nextInteger(); What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0"); else System.out.println("x equals 0"); A. x is greater than 0 B. x is less than 0 C. x equals 0...
Question 21 Which of the following expression yields an integer between 0 and 100, inclusive? A. (int)(Math.random() * 100) B. (int)(Math.random() * 101) C. (int)(Math.random() * 100) + 1 D. (int)(Math.random() * 100 + 1 Question 23 The not equal comparison operator in Java is ________. A. != = B. <> C. ^= D. != Question 24 What is the output of the following fragment? for (int i = 0; i < 15; i++) { if (i % 4 ==...
Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...
(a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) { System.out.println ("Hello"); x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) { sum = sum + i; i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...
Can you help me rearrange my code by incorporating switch I'm not really sure how to do it and it makes the code look cleaner. Can you help me do it but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string,...
QUESTION 7 Which of the following is a valid C++ assignment statement? (assume each letter is a different variable) A.y=b-c B.y +z = x C.x = a bi D.x = -(y*z): Ex = (x + (y z): QUESTION 8 Which of the following is a valid variable name according to C++ naming rules? A 2ndName B.%Last_Name C@Month D#55 Eyear03 QUESTION 9 Which library must be included to enable keyboard input? A kbdin B. cstdlib C input Diostream E lomanip QUESTION...
Can you help me rearrange my code to make it look cleaner but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string, double and int array containing * the command line arguments. * @exception Any exception * @return an arraylsit of...
Java Questions When creating a for loop, which statement will correctly initialize more than one variable? a. for a=1, b=2 c. for(a=1, b=2) b. for(a=1; b=2) d. for(a = 1&& b = 2) A method employee() is returning a double value. Which of the following is the correct way of defining this method? public double employee() c. public int employee() public double employee(int t) d. public void employee() The ____ statement is useful when you need to test a...
Multiple Choice Identify the choice that best completes the statement or answers the que 1. Which of the following is a valid Java identifier? Spay b. 4myGrade! c. newGrade! d. 1dollar static final int EndVal-1: int double; int num console.nextInt(); while (num != Endval) double num * 2; System.out.println (double); num console.next1nt(); 2. The above code is an example of a(n)--while loop. a. flag-controlled b. counter-controlled c. EOF-controlled d. sentinel-controlled 3. The length of the string "first java program" is:...
in JAVA
24. Suppose that a class has an overloaded method named add with the following two implementations: double add (int x, double y) { return x + y; } double add (double x, int y) { return x + y + 1; } What, if anything, will be returned by the following method calls? A. add(3, 3.14) B. (3.14, 3) C. add (3, 3) D. add (3.14, 3.14) 29. Here is the code for a recursive method named mystery....