Question: Using intelliJ There will be four program arguments passed into the main method as a String array in the variable object named args. Remember they
Using intelliJ
There will be four program arguments passed into the main method as a String array in the variable object named args. Remember they get passed in as String type so you might need to parse them into a different types if you want to use them as as different data type like boolean, double, or integers. Below are the methods that can perform parsing.
- boolean a = Boolean.parseBoolean("true"); //a would equal a value of true
- boolean b = Boolean.parseBoolean("yes"); //b would equal a value of true
- int c = Integer.parseInt("9"); //c would equal a value of 9
- double d = Double.parseDouble("5"); //d would equal a value of 5.0
In the main() method create four code sections that perform the following functions.
- if expression: if it matches the program argument value 1 passed-in then print the value matched
- if-else expression: if it matches the program argument value 2 passed-in then print if the value matched or not matched
- if expression with a boolean condition: if it matches the Boolean (values - true or false, yes or no) program argument value 3 passed in, then the code block will print the boolean value
- switch statement: Using the program argument value 4 passed in find the value in the switch and print the value one, two, three. Check only for 1-3 program argument values.
if the input argument value is 1 then print 1
if the input argument value is 2 then print 2
if the input argument value is 3 then print 3
You have to pass in the Program arguments by first setting up the Menu Bar -> Run-> Edit Config -> Program Arguments
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
