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
Alexus [3.1K]
3 years ago
11

Explain the process of creating a switch statement to replace an if-then-else statement in Java.

Computers and Technology
1 answer:
musickatia [10]3 years ago
7 0

Answer:

The answer to this question is given in the explanation section.

Explanation:

Let look at an if the else statement

if (condition1) {

 //some code if condition 1 is true

} else if (condition2) {

 // some code if condition 2 is true

} else {

 // some code if condition 3 is true

}

No let look at switch statement

switch(expression) {

 case x:

   // code block

   break;

 case y:

   // code block

   break;

 default:

   // code block

Now let look at your answer.

if then else should be replaced with switch if conditions are fixed.

in the process of replacing

write your condition of if statement  in the case area of swatch

You might be interested in
Some people are unable to arrange six matches to form four equilateral triangles because they fail to consider a three - dimensi
Andre45 [30]

Answer:

a. fixation

Explanation:

Fixation, also called functional fixedness, is one of the most common factors that limit the ability of people to solve a problem. In this cognitive bias, a person is only able to use objects in ways they are normally used. Any attempt to use it in other ways to solve a problem is almost impossible.

Fixation really affects creativity. It limits the way people think. It makes people have a parochial view of the way an object can be used. It blocks the thinking ability from seeing alternative approaches to solving a problem.

3 0
4 years ago
In order for two computers to communicate via the internet, they must first locate one another. How do computers locate one anot
PolarNik [594]

by the IP address of the computer

a computer is located by the IP address

6 0
3 years ago
Create a program that will play the “cows and bulls” game with the user. The game works like this: Randomly generate a 4-digit n
riadik2000 [5.3K]

Answer:

Welcome to the Cows and Bulls Game!

 Enter a number:

 >>> 1234

 2 cows, 0 bulls

 >>> 1256

 1 cow, 1 bull

 ...

"""

import random

def compare_numbers(number, user_guess):

   cowbull = [0,0] #cows, then bulls

   for i in range(len(number)):

       if number[i] == user_guess[i]:

           cowbull[1]+=1

       else:

           cowbull[0]+=1

   return cowbull

if __name__=="__main__":

   playing = True #gotta play the game

   number = str(random.randint(0,9999)) #random 4 digit number

   guesses = 0

   print("Let's play a game of Cowbull!") #explanation

   print("I will generate a number, and you have to guess the numbers one digit at a time.")

   print("For every number in the wrong place, you get a cow. For every one in the right place, you get a bull.")

   print("The game ends when you get 4 bulls!")

   print("Type exit at any prompt to exit.")

   while playing:

       user_guess = input("Give me your best guess!")

       if user_guess == "exit":

           break

       cowbullcount = compare_numbers(number,user_guess)

       guesses+=1

       print("You have "+ str(cowbullcount[0]) + " cows, and " + str(cowbullcount[1]) + " bulls.")

       if cowbullcount[1]==4:

           playing = False

           print("You win the game after " + str(guesses) + "! The number was "+str(number))

           break #redundant exit

       else:

           print("Your guess isn't quite right, try again.")

Explanation:

7 0
4 years ago
Mauricio plans on retiring in 20 years, and he wants to double his money by that time. He has contacted various banks, looking f
Novosadov [1.4K]

The rule of 72 is a very simple way to estimate and determine the number of years required to double your investments given a fixed annual rate of interest. It can also estimate and then calculate the annual interest rate required to double an investment in a given number of years. In the rule of 72, you can either choose to calculate the annual interest rate or the number of years.  

Use this formula to calculate the rule of 72

Rule of 72  ≈ 72 ÷ interest rate ≈ number of years to double

7 0
3 years ago
Which of the following statements is false? A constructor is similar to a method but is called implicitly by the new operator to
Volgvan

COMPLETE QUESTION:

Which of the following statements is false?

A) A constructor is similar to a method but is called implicitly by the new operator to initialize an object's instance variables at the time the object is created.

B0 Scanner method next reads characters until any white-space character is encountered, then returns the characters as a String.

C)A class instance creation expression begins with keyword new and creates a new object.

D) To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments.

Answer:

D) To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments.

Explanation:

To call a method, the name of the object is not followed by a comma (,) but with a dot (.) operator, the method's name and a set of parentheses containing the method's arguments, then follows.

4 0
3 years ago
Other questions:
  • Consider a load-balancing algorithm that ensures that each queue has approximately the same number of threads, independent of pr
    14·1 answer
  • The number of credits awarded for the CLEP exam is determined by__<br> Help pls!
    15·1 answer
  • What career cluster does a fish and game warden fall in?
    14·1 answer
  • Which company became a digital media leader in 2013 as a result of its horizontally integrated distribution system that branched
    12·1 answer
  • _________ mode is similar to Cipher Feedback, except that the input to the encryption algorithm is the preceding DES output. A.
    11·1 answer
  • ​ In addition to using national weather sites, you should supplement the local weather information with all of the following EXC
    12·1 answer
  • Which feature is used to help identify the appropriate content for particular form fields?
    9·1 answer
  • To copy an item, you would:
    15·2 answers
  • When entering numbers that start with a zero, apply the _____ number format.
    12·1 answer
  • An e-commerce client is moving from on-premise, legacy systems to a cloud-based platform. During the transition, the client is a
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!