Advertisement
daniel_lawson9999

Daniel Lawson Chapter 5 Self Check 14-22 even

May 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. 14.
  2. a. true
  3. b. true
  4. c. false
  5. d. true
  6. e. true
  7. f. false
  8. g. false
  9. h. true
  10. i. true
  11. j. true
  12. k. true
  13. l. false
  14.  
  15. 16.
  16. the else statement is redundant and will mess up the value that the method will return (Should be removed). For example with 16,
  17. it will return that 8 is a factor of 16, making prime false, but when the for loop reaches a number like 9, it will set the
  18. value of prime to true when it should be false.
  19.  
  20. 18.
  21. original:
  22. public static boolean startsEndSame(String str){
  23.     if(str.charAt(0) == str.charAt(str.length() - 1)){
  24.         return true;
  25.     }
  26.     else{
  27.         return false;
  28.     }
  29. }
  30. improved:
  31. public static boolean startsEndSame(String str){
  32.     return(str.charAt(0) == str.charAt(str.length() - 1));
  33. }
  34.  
  35. 20.
  36. mystery(3,3) = 3
  37. mystery(5,3) = 1
  38. mystery(2,6) = 2
  39.  
  40. 22.
  41. a. !b
  42. b.  (x<+y) || (z<+y)
  43. c. (x!=y) && (z>=x)
  44. d. (x % 2 = 0) || !b
  45. e. (x/2 !=13) && !b && (z*3!=96)
  46. f. (z>=x) || (y>=z && y < x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement