Question: Write a Java program which reads a positive integer as a command line argument, then displays the sum of all even values up to

Write a Java program which reads a positive integer as a command line argument, then displays the sum of all even values up to and including the value provided, followed by the sum of all odd values up to and including the value provided. validate that the command line argument is an integer greater than 0 to validate the type, use Integer.parseInt() with a try/catch for NumberFormatException use one or more for loops to perform the even and odd sum calculations Expected console output follows. Command line argument shown in red. Output was generated by multiple runs of the program to test input validation. D:\COP2800C> java Sums 0 Value entered is 0 0 is out of range. D:\COP2800C> java Sums -1 Value entered is -1 -1 is out of range. D:\COP2800C> java Sums 5.5 Value entered is 5.5 5.5 is not an integer. D:\COP2800C> java Sums hello Value entered is hello hello is not an integer. D:\COP2800C>java Sums 5 Value entered is 5 The sum of the even numbers up to 5 is 6 The sum of the odd numbers up to 5 is 9
Step by Step Solution
3.31 Rating (148 Votes )
There are 3 Steps involved in it
Heres a Java program that reads a positive integer as ... View full answer
Get step-by-step solutions from verified subject matter experts
