Question

User enters a flag name. Use a switch statement to chick if the name is one...

User enters a flag name. Use a switch statement to chick if the name is one of 4 possibilities. Include a default condition

0 0
Add a comment Improve this question Transcribed image text
Answer #1

flag = "name"

switch(flag){

case "name1" :

//set of statements

break;

case "name2":

//set of statements

break;

case "name3":

//set of statements

break;

case "name4":

//set of statements

break;

default:

//set of statements

}

swich case checks whether the given value is equal to any one of the values and if they are equal the particular block of statements are executed. Each case sholud contain a break statement to come out the case block.

default statement is executed when there are no matches

Add a comment
Know the answer?
Add Answer to:
User enters a flag name. Use a switch statement to chick if the name is one...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program which asks the user to enter an integer. Use switch statement to write...

    Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...

  • 1) Create a main() method with a switch statement that calls either a sum() OR factorial()...

    1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what selection the user of the program makes - ask the user to enter a selection (with System.out.println()), create a Scanner then read the user's input with a call to Scanner next(), then call the appropriate method in a switch (the String that was read from the call to Scanner.next() should be what you use as your switch condition). 2) Create...

  • Write a C code to calculate the following piecewise function using switch. Assume user enters x (...

    Help needed in c program ! Thannx Write a C code to calculate the following piecewise function using switch. Assume user enters x (a real number) tan(x +1) 10 f(x) =,x = 0 x <0 Write a C code to calculate the following piecewise function using switch. Assume user enters x (a real number) tan(x +1) 10 f(x) =,x = 0 x

  • PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do...

    PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...

  • Use a switch statement to build a menu-driven calculator

    ENGR 40 PROGRAMMING ASSIGNMENT MENU-DRIVEN CALCULATOR PROGRAM Use a switch statement to build a menu-driven calculator. Your program should ask the user to choose from a list of ten possible functions (square root, square, natural log, common log, e'x yx, 1/x, sin(x), cos(x), and tan(x). Each choice will correspond to an integer -example: (1) square root, (2) square, etec. Once the person has input a function choice then a switch statement will control the flow of the program- ie. the program...

  • Write a MIPS program to demonstrate the operation of the following switch statement. switch (S) {...

    Write a MIPS program to demonstrate the operation of the following switch statement. switch (S) { case 5: A = A + 1; break; case 25: A = A - 1; break; default: A = A * 2; break; } Implement and simulate your solution. Allocate .data locations for the variables S and A, and load these values into registers before performing the switch statement on the registers. Run your program several times with different values for these variables, to...

  • Write a C code using switch statement that will ask the user to enter a character....

    Write a C code using switch statement that will ask the user to enter a character. This character should be one of the first three characters of your name. The code then should check for the value of the character and output the following: If the character is the same as yo&r first letter then output "X=10" If the character is the same as your second letter then output "Y=5" If the character is the same as your Third letter...

  • Pick a switch statement from the reading. Put it into a main() Java program and make...

    Pick a switch statement from the reading. Put it into a main() Java program and make it work. Attach the .java file and copyAndPaste the output into the WriteSubmissionBox The switch Statement S1.51 Multiway if-else statements can become unwieldy when you must choose from among many possible courses of action. If the choice is based on the value of an integer or character expres- sion, the switch statement can make your code easier to read. The switch statement begins with...

  • Design JavaFX application with 7 labels and one textfield where user enters input inches. When user...

    Design JavaFX application with 7 labels and one textfield where user enters input inches. When user enters his choice and presses enter key to complete input, program outputs resulting yards, feet, and inches. Use class P5 that extends Application with start method in it, and class P5Pane that extends GridPane. The only instance variables for P5Pane class are inputInches where user enters input inches, and three labels: outYards, outFeet, and outInches where program displays result of conversion. Use the following...

  • Write a Python program that keeps reading in names from the user, until the user enters...

    Write a Python program that keeps reading in names from the user, until the user enters 0. Once the user enters 0, you should print out all the information that was entered by the user. Use this case to test your program: Input: John Marcel Daisy Samantha Nelson Deborah 0 ================ Output: John Marcel Daisy 25 Samantha Nelson Deborah Hints: Create an array Names to hold the input names. Use the Names.append(x) function to add a new name to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT