2. Learning the Basics
Activity 1: Taking Input and Comparing Ranges
Solution
- In
main()
, introduce anif
statement to check if the arguments entered are of the right length:public class Activity1 { Â Â Â Â public static void main(String[] args) { Â Â Â Â Â Â Â Â if (args.length < 2) { Â Â Â Â Â Â Â Â Â Â Â Â System.err.println("Error. Usage is:"); Â Â Â Â Â Â Â Â Â Â Â Â System.err.println("Activity1 systolic diastolic"); Â Â Â Â Â Â Â Â Â Â Â Â System.exit(-1); Â Â Â Â Â Â Â Â }
- Parse these arguments as
int
values and save them in variables:        int systolic  = Integer.parseInt(args[0]);         int diastolic = Integer.parseInt(args...