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; }

Answers

Answer 1

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

Related Questions

Other Questions
Maria bought an SUV for 21,000 dollars. Nancy bought a sedan for 2/3 as much. How much less did Nancy spend on her sedan? A Physics question regarding circuits and electricity. 7h=-(2h-18)7h=(2h18) Solve for h Find an explicit formula for the geometric sequence 3, 15, 75, 375... Bob, Kara, and Mark are partners in the BKM Partnership. Bob is a 40% partner and has a June 30 tax yearminusend. Kara owns a 40% interest in the partnership and has a September 30 tax yearminusend, and Mark owns the remaining 20% interest and has an October 31 tax yearminusend. The partnership does not have a natural business year. What is the required tax yearminusend for the partnership (if no Sec. 444 election is made)? A. September 30 B. October 31 C. December 31 D. June 30 Language Arts Help Please!I need 2 actions that increase the conflict from the charecters Scout and Bob Ewell from the book "To KIll A Mocking Bird" The length of a rectangle is 5 m less than twice the width, and the area of the rectangle is 52m ^ 2 . Find the dimensions of the rectangle. Math question down below Which statement best describes Johnsons treatment of the underlined word? A. Johnson uses the word to criticize established publications. B. Johnson uses the word to express indifference about written material.C. Johnson uses the word so assert his admiration for published writing.D. Johnson uses the word to suggest that his writing is worthy of high praise. Determinado automovel, apos sua compra, perde 10% do valor ano a ano nos 3 preimeiros anos. Calcule o valor do automovel ao final desse periodo sabendo que ele foi comprado por R$80.000 Compare and contrast the dynamics of energy transfer between the Eocene Period and the Cryogenian Period. In which period would you say that Earth's system is experiencing a net gain in energy and in which period would you say that Earth's system is experiencing a net loss in energy The changing of the rivers created more ____________ for animals aRegeneration bVegetation c Erosion d Habitats Ramesh examined the pattern in the table. Powers of 7 Value 7 Superscript 4 2,401 7 Superscript 3 343 7 Superscript 2 49 7 Superscript 1 7 7 Superscript 0 1 7 Superscript negative 1 StartFraction 1 Over 7 EndFraction Ramesh says that based on the pattern 7 Superscript negative 5 = negative 16,807. Which statement explains whether Ramesh is correct? Ramesh is correct because 7 Superscript negative 5 is equivalent to Negative 7 times (negative 7) times (negative 7) times (negative 7) times (negative 7), which has the same value as Negative 16,807. Ramesh is correct because as the exponents decrease, the previous value is divided by 7, so 7 Superscript negative 5 = 1 divided by 7 divided by 7 divided by 7 divided by 7 divided by 7 = negative 16,807. Ramesh is not correct because 7 Superscript negative 5 is equivalent to StartFraction 1 Over 7 Superscript 5 EndFraction, which has the same value as StartFraction 1 Over 7 Superscript 4 EndFraction divided by 7 = StartFraction 1 Over 7 cubed EndFraction = StartFraction 1 Over 343 EndFraction. Ramesh is not correct because as the exponents decrease, the previous value is divided by 7, so 7 Superscript negative 5 = 1 divided by 7 divided by 7 divided by 7 divided by 7 divided by 7 = StartFraction 1 Over 16,807 EndFraction. NEED HELP NOW PLEASE I HAVE ONLY SEEN WRONG ANSWERS Please help worth 20 points!! how old was Thomas Jefferson when he died 0.450 moles of K2SO4 are dissolved in 195.0 mL of water. Calculate the molarity of the solution. Please answer this correctly and i will mark you as brainlist and give you 100 points. I dont understand this question please help A cell phone and phone case cost $110 in total. The cell phone costs $100 more than the phone case. How much was the cell phone? Write a statement that calls the recursive method backwardsAlphabet() with parameter startingLetter. import java.util.Scanner; public class RecursiveCalls { public static void backwardsAlphabet(char currLetter) { if (currLetter == 'a') { System.out.println(currLetter); } else { System.out.print(currLetter + " "); backwardsAlphabet((char)(currLetter - 1)); } } public static void main (String [] args) { Scanner scnr = new Scanner(System.in); char startingLetter; startingLetter = scnr.next().charAt(0); /* Your solution goes here */ } }