Question: Java Question about user input and switch statements. Let's say I have a program that will continuously prompt the user to enter one of sever
Java Question about user input and switch statements.
Let's say I have a program that will continuously prompt the user to enter one of sever possible commands in order to modify a linked list (prepend, append, display, modify, etc). Based on what they enter, one of those several cases within the switch statement will call its respective method (prepend, append modify, display, etc). It will do this continoualy until the user enters q, which will quit the program. However, some of the commands and their corresponding methods will need additional parameters passed. My question is how can I properly pass those values onto those several methods for which you need to pass in different parameters (how do I split up what the user inputs up) ? An example is if the user wanted the list to be prepend (and need to pass it two different values), the user would type "P 1 2". But how do I call prepend within case P and pass on 1 and 2 for the first and second parameter respectively? We assume the user would enter in all needed information and on the same line.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
