1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
shepuryov [24]
3 years ago
13

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 &g

t; 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; }
Computers and Technology
1 answer:
Tanya [424]3 years ago
3 0

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 Java
  • The 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
You might be interested in
ANSWER QUICKLY!!! <br><br> What is an advantage of digital portfolios?
algol13
Easy to carry or utilize
8 0
1 year ago
The function below takes one parameter: a string (date_string) containing a date in the mm/dd/year format. Complete the function
Natalija [7]

Answer:

The solution code is written in Python 3.

  1. def convertDate(date_string):
  2.    date_list = date_string.split("/")
  3.    for i in range(0, len(date_list)):
  4.        date_list[i] = int(date_list[i])
  5.    return date_list  
  6. print(convertDate('06/11/1930'))

Explanation:

Firstly, create a function convertDate() with one parameter, <em>date_string</em>. (Line 1).

Next, use the Python string <em>split()</em> method to split the date string into a list of date components (month, day & year) and assign it to variable <em>date_list</em>. (Line 3) In this case, we use "/" as the separator.

However, all the separated date components in the <em>date_list</em> are still a string. We can use for-loop to traverse through each of the element within the list and convert each of them to integer using Python<em> int() </em>function. (Line 5 - 6)

At last return the final date_list as the output (Line 8)

We can test our function as in Line 11. We shall see the output is as follow:

[6, 11, 1930]

8 0
2 years ago
A user can set the security and privacy settings on what is displayed in the message bar from the ________ within the options me
djverab [1.8K]
Depends on the Operating System
6 0
3 years ago
Gal runs a music store. He has a desktop computer in the back room that acts as a server. He has a point-of-sale terminal that c
Masja [62]

Answer:

The answer is letter C. The letter C is the true statement.

Explanation:

The true statement is The point-of-sale terminal cannot connect directly to the Internet.

8 0
3 years ago
Plz answer me will mark as brainliest ​
victus00 [196]

Answer:

Application

Explanation:

Application software comes in many forms like apps, and even on computers. The software is most common on computers of all kinds while mobile applications are most common on cellular devices.

3 0
3 years ago
Read 2 more answers
Other questions:
  • You can use Facebook's live feed tool to broadcast content as you post it
    8·2 answers
  • Liz will use a CD-R compact disk to write to more than once. Carlo will use a CD-RW compact disk to write to more than once. Who
    8·2 answers
  • why do programs include keyboard shortcuts for certain actions? do you prefer the mouse or the keyboard/ why?
    7·1 answer
  • How might writing an online journal be different than writing in a paper one ​
    15·2 answers
  • What is a gutter margin?
    5·2 answers
  • The picture that graphically represents the items you use in windows is called a/an
    5·1 answer
  • You can minimize the Ribbon with a command contained on the _____.
    7·1 answer
  • A source is:
    15·2 answers
  • Which is the correct notation to specify the following inheritance?
    8·1 answer
  • What is the answer in music class
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!