65 792
Assignments Done
99,4%
Successfully Done
In October 2018

Answer to Question #62009 in Java | JSP | JSF for Bill DeShields

Question #62009
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.
Expert's answer
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions