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...