1. Write a nested if else statement that will compare the values of total and MA
ID: 3606371 • Letter: 1
Question
1. Write a nested if else statement that will compare the values of total and MAX. If the values of total and MAX are equal, compare the values of total and sum, if total is less than sum print a message that states total and MAX are equal and total is less than sum. If the values of total and MAX are not equal print a message that total is not equal to MAX.
2. Assume num is of type int and myChar is of type char.Write a nested if else statement that will do the following:
if num is equal to 5 assign myChar to W
if num is equal to 6 assign myChar to X
if num is equal to 7 assign myChar to Y
otherwise assign myChar to Z
3. Use a switch statement to solve #2.
Explanation / Answer
//Java Code
1).
if (total == MAX) {
if (total < sum) {
System.out.println("total and MAX are equal and total is less than sum");
}
} else {
System.out.println("total is not equal to MAX");
}
2).
if (num == 5) {
myChar = 'W';
} else if (num == 6) {
myChar = 'X';
} else if (num == 7) {
myChar = 'Y';
} else {
myChar = 'Z';
}
3).
switch(num){
case 5:
myChar = 'W';
break;
case 6:
myChar = 'X';
break;
case 7:
myChar = 'Y';
break;
default:
myChar = 'Z';
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.