Concept explainers
Convert the following if-else-if statement into a switch statement:
if (choice == 1)
{
System.out.println(“You selected 1.”);
}
else if (choice == 2 || choice == 3)
{
System.out.println(“You selected 2 or 3.”);
}
else if (choice == 4)
{
System.out.println(“You selected 4.”);
}
else
{
System.out.println(“Select again please.”);
}
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out with Java: Early Objects (6th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with C++: Early Objects
Modern Database Management (12th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out With Visual Basic (8th Edition)
- Convert the following if-else-if statement into a switch statement if(choice==1) { System.out.println ("Its a 1."); } else if(choice==2 || choice==3) { System.out.println ("Its a 2 or 3"); } else if(choice==4) { System.out.println ("Its a 4"); else { System.out.println ("um, try again 1 4"); - }arrow_forwardRewrite the following using if-else-if structure. k=2; switch (i) case 0: k+=i; break; case 1: k*=i; break; case 2: case 3: k/=i; break; default: k%=i;arrow_forward3. Convert the following switch statement into if-else statements then into if-then statements: String dayString1, dayString2, dayString3; int day = KB.nextInt (); switch (day) { case 1: dayStringl case 2: dayString2 "Saturday"; "Sunday"; break; case 3: dayString3 = "Monday"; break; case 4: dayStringl = "Tuesday"; case 5: daystring2 = "Wednesday"; break; default: dayString3 = "Invalid day"; break; } 4. Write a program that displays the following pattern: A A A A BB AA A ССС AA AA DDDD AAAΑ EEEEE ΑAAAΑΑ FFFFFFarrow_forward
- Write a statement that assigns finalValue with the multiplication of userNum1 and userNum2. Ex: If userNum1 is 6 and userNum2 is 2, finalValue is 12. let userNum1 = 6; // Code tested with values: 6 and 4let userNum2 = 2; // Code tested with values: 2 and -2 let finalValue = 0;arrow_forwardRewrite the if else-if statement using a switch statement: if (fruit 'p' || fruit 'P') == рарayat+; else if (fruit 'b' || fruit 'B') == banana++; else if (fruit 'm' || fruit 'M') == == mango++; else printf("Invalid entry\n");arrow_forwardUsing the following chart, write an if-else-if statement that assigns: S, M, L, depending on the weight: Weight Size Up to 120 lb S 120 lb to 175 lb M Over 175 lb Larrow_forward
- Rewrite the following statement with an if/else statement: total += count = = 1? sales : count * sales;arrow_forwardImplement the following decision table using a nested if statement and multiple alternatives if statement. Assume that the grade point average is within the range 0.0 through 4.0. Do not write entire program. Mention only the required variables and the nested if statement. Grade Point Average Transcript Message 0.0-0.99 Failed semester-registration suspended 1.0–1.99 On probation for next semester 2.0-2.99 (no message) 3.0-3.49 Dean's list for semester 3.5-4.00 Highest honors for semesterarrow_forwardImplement the following decision table using a nested if statement and multiple alternatives if statement. Assume that the grade point average is within the range 0.0 through 4.0. Do not write entire program. Mention only the required variables and the nested if statement. grade point average transricpt message 0.0-0.99 failed semester - resigister suspended 1.0- 1.99 on probation for next semester 2.0-2.99 (no message) 3.0-3.49 dean's list for semester 3.5-4.00 highest honors for semesterarrow_forward
- Write an if-else statement that works like this: If the sales variable is greaterthan or equal-to 50,000, the commissionRate variable should be assigned the value 0.2. Otherwise, the commissionRate variable should be assigned the value 0.1.arrow_forwardTrue or False? Every if statement must have a corresponding else.arrow_forwardWrite an if statement that assigns 20 to the variable y, and assigns 40 to the variable z if the variable x is greater than 100. Write an if statement that assigns 0 to the variable b, and assigns 1 to the variable c if the variable a is less than 10. Write an if-else statement that assigns 0 to the variable b if the variable a is less than 10. Otherwise, it should assign 99 to the variable b. Write nested decision structures that perform the following: If amount1 is greater than 10 and amount2 is less than 100, display the greater of amount1 and amount2.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT