Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 14.
- a. true
- b. true
- c. false
- d. true
- e. true
- f. false
- g. false
- h. true
- i. true
- j. true
- k. true
- l. false
- 16.
- the else statement is redundant and will mess up the value that the method will return (Should be removed). For example with 16,
- 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
- value of prime to true when it should be false.
- 18.
- original:
- public static boolean startsEndSame(String str){
- if(str.charAt(0) == str.charAt(str.length() - 1)){
- return true;
- }
- else{
- return false;
- }
- }
- improved:
- public static boolean startsEndSame(String str){
- return(str.charAt(0) == str.charAt(str.length() - 1));
- }
- 20.
- mystery(3,3) = 3
- mystery(5,3) = 1
- mystery(2,6) = 2
- 22.
- a. !b
- b. (x<+y) || (z<+y)
- c. (x!=y) && (z>=x)
- d. (x % 2 = 0) || !b
- e. (x/2 !=13) && !b && (z*3!=96)
- f. (z>=x) || (y>=z && y < x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement