Question
4. Consider the following method, between, which is intended to return true if x is between lower and upper, inclusive, and false otherwise. //precondition: lower
4. Consider the following method, between, which is intended to return true if x is between lower and upper, inclusive, and false otherwise.
//precondition: lower <= upper //postcondition: returns true if x is between lower and upper, // inclusive; otherwise, returns false public boolean between(int x, int lower, int upper) { /*missing code */ }
Which of the following can be used to replace /* missing code */ so that between will work as intended?
Question 4 options:
return (x <= lower) || (x >= upper); | |
return (x >= lower) || (x <= upper); | |
return (x <= lower) && (x >= upper); | |
return (x >= lower) &&(x <= upper); | |
return lower <= x <= upper; |
5. Consider the following class declaration.
public class IntCell { private int myStoredValue; //constructor not shown public int getValue() { return myStoredValue; }
public String toString() { return "" + myStoredValue; } }
Assume that the following declarations appears in a client class.
IntCell m = new IntCell(); Which of these statements can be used in the client class?
I. System.out.println (m.getValue());
II. System.out.println (m.myStoredValue);
III. System.out.println (m);
Question 5 options:
III only | |
II only | |
I and II | |
I only | |
I and III |
6. Consider the following method.
public void conditionalTest(int a, int b) { if (( a > 0) && ( b > 0)) { if (a > b) System.out.println ("A"); else System.out.println ("B"); } else if ((b < 0) || (a < 0)) System.out.println("C"); else System.out.println ("D"); }
What is printed as a result of the call conditionalTest(3, -2)?
Question 6 options:
C | |
B | |
Nothing is printed. | |
A | |
D |
Step 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