A For each of the following output values give the range of
A. For each of the following output values, give the range of values for the variable x that will cause the segment to display the given String. For example, if anything between 0 and 10 including both 10 and zero will produce the string, your answer should be 0<=x<=10. If a value can never be produced by this code, give a short single sentence explanation of why not
1. “Apple pie”
2. “Brownies”
3. “Cherry Pie”
4. “Dark Chocolate Cake”
5. “Espresso Cake”
6. “Fruit Custard”
B. Consider the following code segment where x is a variable of type int:
if (x > 55 ) {
if (x < 80) {
System.out.println(“Fruit Custard”);
}
else {
System.out.println(“Brownies”);
}
}
else if (x > 22) {
if (x < 60){
System.out.println(“Espresso Cake”);
}
else {
System.out.println(“Apple pie”);
}
}
else if (x < 25) {
System.out.println(“Dark Chocolate Cake”);
}
else { System.out.println(“Cherry Pie”); }
Solution
1) can\'t product Apple pie
because acc to first if condition value of x shud be less than equal to 55. and second if condition value of x is greator than 60 . hence both the condition will contradict each other.
2) x>=80
3)can\'t product cherry pie because it will never come to last else condition
4) x<=22
5) 22<x<=55
6) 55<x<80


