Question
Working on Switch multiple-selection statements. code figure 4.9 as an example on page 124-125 Create a program that asks the user for a number between
Working on Switch multiple-selection statements.
code figure 4.9 as an example on page 124-125
Create a program that asks the user for a number between 1 and 5. Use the number they enter to select a printout from your switch/case to print out one thing you learned about the topic. Code must include a default case for when the user enters a number that is not on the list.
This is what I have come up with the code that we have to reference. Problem is that it says it is a successful build but now I can even get it to run. And even when it was running it was not doing what I asked. Any help would be greatly appreciated.
import java.util.Scanner;
/** * * */ public class Chapt4disc {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here //initialize int funFact = 0; int aFact = 0; int bFact = 0; int cFact = 0; int dFact = 0; int eFact = 0; int fFact = 0; //start scanner Scanner input = new Scanner(System.in); //print out asking for user input System.out.printf("%s%n %s", "Enter integers 1 through 5.", "One integer on each line."); //while statement relating input to fact while (input.hasNext()) { int fact = input.nextInt();//input ++funFact; switch (fact) { case 5://input equals 5 ++aFact; break; case 4://inout equals 4 ++bFact; break; case 3://input equals 3 ++cFact; break; case 2://input equals 2 ++dFact; break; case 1: //input equals 1 ++eFact; default://other then 1 through 5 ++fFact; break; }//end switch }//end while System.out.printf( "%n1: Internet of things doesn't have a clear definition. %n", aFact, "%n2: The smart industry is the most prominent example of IOT.%n", bFact, "%n3: IOT is characterized by the combination of physical and digital " + "components to create new products and enable novel business models. %n", cFact, "%n4: IOT typically combines a physical thing with IT in the form of hardware and software. %n", dFact, "%n5: IOT can increase the opportunities of threats.%n ", eFact); }//END OF MAIN }//END OF CLASS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started