Answer:
The formula used in this question is called the probability of combinations or combination formula.
Explanation:
Solution
Given that:
Formula applied is stated as follows:
nCr = no of ways to choose r objects from n objects
= n!/(r!*(n-r)!)
The Data given :
Menu A : 5 appetizers and 3 main dishes
Menu B : 3 appetizers and 4 main dishes
Total appetizers - 6
Total main dishes - 5
Now,
Part A :
Total ways = No of ways to select menu A + no of ways to select menu B
= (no of ways to select appetizers in A)*(no of ways to select main dish in A) + (no of ways to select appetizers in B)*(no of ways to select main dish in B)
= 6C5*5C3 + 6C3*5C4
= 6*10 + 20*5
= 160
Part B :
Since, we can select the same number of appetizers/main dish again so the number of ways to select appetizers/main dishes will be = (total appetizers/main dishes)^(no of appetizers/main dishes to be selected)
Total ways = No of ways to select menu A + no of ways to select menu B
= (no of ways to select appetizers in A)*(no of ways to select main dish in A) + (no of ways to select appetizers in B)*(no of ways to select main dish in B)
= (6^5)*(5^3) + (6^3)*(5^4)
= 7776*125 + 216*625
= 1107000
Part C :
No of ways to select same appetizers and main dish for all the options
= No of ways to select menu A + no of ways to select menu B
= (no of ways to select appetizers in A)*(no of ways to select main dish in A) + (no of ways to select appetizers in B)*(no of ways to select main dish in B)
=(6*5) + (6*5)
= 60
Total ways = Part B - (same appetizers and main dish selected)
= 1107000 - 60
= 1106940
Rewrite this if/else if code segment into a switch statement int num = 0; int a = 10, b = 20, c = 20, d = 30, x = 40; if (num > 101 && num <= 105) { a += 1; } else if (num == 208) { b += 1; x = 8; } else if (num > 208 && num < 210) { c = c * 3; } else { d += 1004; }
Answer:
public class SwitchCase {
public static void main(String[] args) {
int num = 0;
int a = 10, b = 20, c = 20, d = 30, x = 40;
switch (num){
case 102: a += 1;
case 103: a += 1;
case 104: a += 1;
case 105: a += 1;
break;
case 208: b += 1; x = 8;
break;
case 209: c = c * 3;
case 210: c = c * 3;
break;
default: d += 1004;
}
}
}
Explanation:
Given above is the equivalent code using Switch case in JavaThe switch case test multiple levels of conditions and can easily replace the uses of several if....elseif.....else statements.When using a switch, each condition is treated as a separate case followed by a full colon and the the statement to execute if the case is true.The default statement handles the final else when all the other coditions are false