OWEN COMPUTER SCIENCE LESSONS 2014-2015 L2RVW4 Pg 1 Lesson 2 Review #4 Name Matching Match each description to the correct data type. a. int e. short b. float f. long c. double g. char d. byte 1. up to 15 decimal places of storage and output precision 2. -32768...32767 3. -2147483648...2147483647 4. 0...65535 5. up to 7 decimal places of storage and output precision 6. -128...127 7. approximately -9 quintillion...9 quintillion Complete each sentence or statement. 8. Classify this statement as valid or invalid. final int x = 5; x = 6; 9. For what two word phrase is bit an abbreviation? 10. The function of the assignment operator (=) is a to process. 11. The term _ indicates that an operator performs a process of some sort on two values or objects. 12. Complete the statement. A Java constant is usually all letters. 13. Indicate the correct value in bits for memory storage for the data type listed. char ==> bits 14. Fill in the blank with the appropriate data type (int, double, String, char, boolean). d = -14.5; 15. What Java limit does this value represent? -9223372036854775808. VALUE 16. Classify this identifier as valid or invalid for use in Java. 8ball
OWEN COMPUTER SCIENCE LESSONS 2014-2015 L2RVW4 Pg 2 17. Classify this statement as valid or invalid. final String n = "Z" 18. Classify this identifier as valid or invalid for use in Java. miles_per_hour 19. Indicate the correct value in bits for memory storage for the data type listed. int ==> bits 20. What is the output of this statement? byte b = -128; b = b-1; System.out.println(b); 21. Fill in the blank with the appropriate data type (int, double, String, char, boolean). hungry = true; 22. What Java limit does this value represent? 127. VALUE 23. What is the operator that checks to see if two pieces of data are equal? Fill in the blanks with the correct output produced by the code segments shown below, as if they were sequential statements all part of the same program. 24. int num1 = 49; int num2 = 7; 25. num1 = -35; num2 = 6; 26. num1 = 24; num2 = -3; 27. num1 = 41; num2 = 3;
OWEN COMPUTER SCIENCE LESSONS 2014-2015 L2RVW4 Pg 3 28. num1 = 93; num2 = 3; 29. num1 = 16; num2 = 5; 30. num1 = 10; num2 = -1; Fill in the blanks with the correct output produced by the code segments shown below as if they were sequential statements all part of the same program. It is possible that not all of the blanks will be used each time. 31. int x = 1; while(x<6) x++; 32. x = 10; while(x>0) x--; 33. x = 4; while(x<20) x+=3;
OWEN COMPUTER SCIENCE LESSONS 2014-2015 L2RVW4 Pg 4 34. x = 30; while(x>=0) x-=5; 35. x = 2; while(x<100) x*=3; 36. x = 100; while(x>0) x/=3; Fill in the blanks with the correct output produced by the code segments shown below, as if they were sequential statements all part of the same program. 37. double dub1 = 24.6; double dub2 = 8.2; System.out.printf("%.1f / %.1f = %.1f\n",dub1,dub2,dub1 / dub2); 38. System.out.printf("%.1f %% %.1f = %.1f\n",dub1,dub2,dub1 % dub2); 39. dub2 = 16.4; System.out.printf("%.1f / %.1f = %.1f\n",dub1,dub2,dub1 / dub2); 40. System.out.printf("%.1f %% %.1f = %.1f\n",dub1,dub2,dub1 % dub2);
OWEN COMPUTER SCIENCE LESSONS 2014-2015 L2RVW4 Pg 5 41. dub1*=-1; System.out.printf("%.1f / %.1f = %.1f\n",dub1,dub2,dub1 / dub2); 42. System.out.printf("%.1f / %.1f = %.1f\n",dub1,dub2,dub1 / dub2); 43. dub1*=-1; dub2*=-1; System.out.printf("%.1f / %.1f = %.1f\n",dub1,dub2,dub1 / dub2); 44. System.out.printf("%.1f %% %.1f = %.1f\n",dub1,dub2,dub1 % dub2); Fill in the blanks with the correct output produced by the code segments shown below, as if they were sequential statements all part of the same program. 45. int num1 = 4; int num2 = 5; System.out.printf("%d / %d = %d\n",num1,num2,num1 / num2); 46. System.out.printf("%d %% %d = %d\n",num1,num2,num1 % num2); 47. num2 = 3; System.out.printf("%d / %d = %d\n",num1,num2,num1 / num2); 48. System.out.printf("%d %% %d = %d\n",num1,num2,num1 % num2); Fill in the blanks with the correct output produced by the code segments shown below as if they were sequential statements all part of the same program. 49. int num = 5; double dub = 2.5; char let = 'E'; System.out.printf("%d %.1f %s\n",num,dub,let); 50. num += 4.6; dub *= 3.8; let += 33; System.out.printf("%d %.1f %s\n",num,dub,let);
OWEN COMPUTER SCIENCE LESSONS 2014-2015 L2RVW4 Pg 6 51. num *= 2.4; dub /= 3.6; let -= 20.3; System.out.printf("%d %.1f %s\n",num,dub,let); 52. num -= '1'; dub += 40; let += 33.5; System.out.printf("%d %.1f %s\n",num,dub,let);
OWEN COMPUTER SCIENCE LESSONS 2014-2015 L2RVW4 Pg 7 Lesson 2 Review #4 Answer Section MATCHING 1. ANS: C 2. ANS: E 3. ANS: A 4. ANS: G 5. ANS: B 6. ANS: D 7. ANS: F 8. ANS: invalid 9. ANS: binary digit 10. ANS: right to left 11. ANS: binary 12. ANS: capital 13. ANS: 16 14. ANS: double 15. ANS: Long.MIN_VALUE 16. ANS: invalid 17. ANS: valid 18. ANS: valid 19. ANS: 32 20. ANS: 127 21. ANS: boolean 22. ANS: Byte.MAX_VALUE 23. ANS: == 24. ANS: 49 divisible by 7: true 25. ANS: -35 divisible by 6: false 26. ANS: 24 divisible by -3: true 27. ANS: 41 divisible by 3: false 28. ANS: 93 divisible by 3: true 29. ANS: 16 divisible by 5: false 30. ANS: 10 divisible by -1: true 31. ANS: 1 2 3 4 5 32. ANS: 10 9 8 7 6 5 4 3 2 1 33. ANS: 4 7 10 13 16 19 34. ANS: 30 25 20 15 10 5 0 35. ANS: 2 6 18 54 36. ANS: 100 33 11 3 1 37. ANS: 24.6 / 8.2 = 3.0
OWEN COMPUTER SCIENCE LESSONS 2014-2015 L2RVW4 Pg 8 38. ANS: 24.6 % 8.2 = 0.0 39. ANS: 24.6 / 16.4 = 1.5 40. ANS: 24.6 % 16.4 = 8.2 41. ANS: -24.6 / 16.4 = -1.5 42. ANS: -24.6 % 16.4 = -8.2 43. ANS: 24.6 / -16.4 = -1.5 44. ANS: 24.6 % -16.4 = 8.2 45. ANS: 4 / 5 = 0 46. ANS: 4 / 5 = 4 47. ANS: 4 / 3 = 1 48. ANS: 4 % 3 = 1 49. ANS: 5 2.5 E 50. ANS: 9 9.5 f 51. ANS: 21 2.6 Q 52. ANS: -28 42.6 r