Answered step by step
Verified Expert Solution
Question
1 Approved Answer
***JAVA ONLY*** Chapter 2 Elementary Programming 1. What is the exact output of the following code? double area = Math.pow (3.5,1); System.out.print(area); System.out.print(area); a. 3.53.5
***JAVA ONLY***
Chapter 2 Elementary Programming 1. What is the exact output of the following code? double area = Math.pow (3.5,1); System.out.print("area"); System.out.print(area); a. 3.53.5 b. 3.53.5 c. area 3.5 d. area 3.5 2. Suppose a Scanner object is created as follows, what method do you use to read a real number? Scanner input = new Scanner(System.in); a. input.nextDouble(); b. input.nextdouble(); c. input.double(); d. input.Double(); 3. Which of the following is a valid identifier? a. $343 b. class c. 9X d. 8+9 e. radius 4. Which of the following are correct names for variables according to Java naming conventions? a. radius b. Radius c. RADIUS d. findArea e. FindArea 5. Which of the following are correct ways to declare variables? a. int length; int width; b. int length, width; c. int length; width; d. int length, int width; 6. Which of the following assignment statements is incorrect? a. i=j=k=1; b. i=1;j=1;k=1; c. i=1=j=1=k=1; d. i==j==k==1; 7. To declare a constant MAX_LENGTH inside a method with value 99.98, you write a. final MAX_LENGTH = 99.98; b. final float MAX_LENGTH = 99.98; c. double MAX_LENGTH = 99.98; d. final double MAX_LENGTH = 99.98; 8. Which of these data types requires the most amount of memory? a. char b. int c. short d. byte 9. What is the result of 45/4 ? a. 10 b. 11 c. 11.25 d. 12 10. Which of the following expression results in a value 2 ? a. 2%10 b. 15%4 c. 25%5 d. 37%6 11. 25%(16%9) is 3. 1 b. 2 c. 3 d. 4 e. 0 12. How do you write 5243 in Java? 3. 243(1/5) b. Math.pow (243,1/5) c. Math.pow (243,5) d. Math.pow (5,243) 13. Analyze the following code. public class Test \{ public static void main(String[] args) \{ int month = 09; System.out.println("month is " + month); \} a. The program displays month is 09 . b. The program displays month is 9 . c. The program displays month is 9.0. d. The program has a syntax error, because 09 is an incorrect literal value. 14. Which of the following is incorrect? a. 1_2 b. 0.4_56 c. 1_200_229 d. _4544 15. Which of the following are the same as 1545.534 ? a. 1.545534e+3 b. 0.1545534e+4 c. 1545534.0e5 d. 154553.4e6 16. Which of the following is incorrect? 3. int x=9; b. long x=9; c. float x=1.0; d. double x=1.0; 17. The command to exit JShell is a. lquit b. lexit c. /quit d. /exit 18. The command to view all variables in JShell is a. lvars b. lvar c. /vars d. /var 19. The System.currentTimeMillis() returns . a. the current time. b. the current time in milliseconds. c. the current time in milliseconds since midnight. d. the current time in milliseconds since midnight, January 1,1970 . e. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time). 20. To obtain the current second, use a. System.currentTimeMillis() %3600 b. System.currentTimeMillis() %60 c. System.currentTimeMillis() / 1000%60 d. System.currentTimeMillis() / 1000/60%60 e. System.currentTimeMillis() / 1000/60/60%24 21. Suppose x is 1 . What is x after x+=2 ? a. 0 b. 1 c. 2 d. 3 e. 4 22. Which of the following statements are the same? (I) x=x+4 (iI) x=x+4x (III) x=x(x+4) a. (I) and (II) are the same b. (I) and (III) are the same c. (II) and (III) are the same d. (I), (II), and (III) are the same 23. What is i printed? public class Test \{ public static void main(String[] args) \{ int j=0; int i=++j+j5; System.out.println("What is i?" " +i ); \} a. 0 b. 1 c. 5 d. 6 24. What is y displayed in the following code? public class Test \{ public static void main(String[] args) \{ int x=1; int y=x+++x; System.out.print In(" y is " +y); \} \} a. y is 1 . b. y is 2 . c. y is 3 . d. y is 4 . 25. Are the following four statements equivalent? number +=1; number = number +1 number++; ++number; a. Yes b. No 26. To assign a double variable d to a float variable x, you write a. x=( long)d b. x=( int )d; c. x=d; d. x=( float ); 27. Which of the following assignment statements is illegal? a. float f=34; b. int t=23; c. short 5=10; d. int t=4.5; 28. Which of the following expression results in 45.37 ? a. (int )(45.378100)/100 b. ( int )(45.378100)/100.0 c. (int) (45.378100/100) d. (int) (45.378)100/100.0 29. If you attempt to add an int, a byte, a long, and a double, the result will be a(n) value. a. byte b. int c. long d. double 30. Suppose int x=3264, what is the output of the following code? int y=x%10;x=x/10; System.out.println(" x is " +x+ " and y is " +y ); a. x is 3264 and y is 326.4 b. x is 326 and y is 326 c. x is 326 and y is 4 d. x is 3264 and y is 4 e. x is 4 and y is 326Step 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