Write a method named sumInts that can take a variable number of int arguments and return the sum of these arguments. The ints to be summed up must be entered as command line arguments. Command line arguments can be simulated in Eclipse. Watch the video. In the main method, display the ints that were entered on the command line. Then execute sumInts and display the sum it returns.
1
Expert's answer
2016-09-14T12:41:03-0400
public class Main {
private static int sumInts(int a, int b){ return a + b; }
public static void main(String[] args) { // write your code here try{ int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); System.out.println("Integers that were entered are: " + a + " and " + b); System.out.println("The sum of this integers is: " + a + " + " + b + " = "+ sumInts(a, b)); }catch (Exception e){ System.out.println("Bad input"); } } }
Comments
Leave a comment