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.
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");
}
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF