Asked Feb 6, 2020

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. In the main method, display the ints that were entered on the command line. Then execute sumInts and display the sum it returns.

Passing [1, 2, 3, 4, 5]
Sum is 15
Passing [10, 20, 30]
Sum is 60

Image Transcriptionclose

TWO SAMPLE OUTPUTS Passing [1, 2, 3, 4, 5] Sum is 15 Passing [10, 20, 30] Sum is 60


Expert Answer

Step 1

 Program Approach:

  • Import the essential Java Packages.
  • Define the Main method.
  • Define the sumInts method.
  • Argument will be provided in the format of integer array type.
  • Use If-Else statement to check the condition.
  • Check for the variables whether they are provided as Command-Line arguments or not.
  • Create an array in the If statement, and a For loop for storing the Command-Line arguments in the num array.
  • Initialize the variables as per the usage in the sumInts method.
  • Use for loop to calculate the value of variable total.
  • Display the result on the console.

Note: Arguments which are passed in the sumInts() function are taken as command-line arguments.

Step 2

Code(in java)-

//Import the essential package

import java.util.*;

// Declaring class

class Main


//defining main method

public static void main(String[] a)


//To determine whether, there are variable arguments in the command line or not

if (a.length!=0)


//Create the object of an array

int[] number = new int[a.length];

for (int i = 0; i < number.length; i++)


//command line arguments into integer type is converted use typecasting

//Store variables in number array

number[i] = Integer.parseInt(a[i]);


//Dsiplaying the result

System.out.println("Executing " + Arrays.toString(number));

System.out.println("The sum is " + sumInts(number));




Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in


Computer Engineering

Related Computer Engineering Q&A

Find answers to questions asked by student like you
Show more Q&A

Q: What fact-finding methods are well suited for complex technical issues? Which might be appropriate f...

A: Fact finding techniques for complex technical issues are:Document ReviewIt is used to confirm with u...


Q: Identify the errors in the following program. 2 errorspublic class Test {public static void main(St...

A: The two errors in the given program are:The argument is passed in wrong order in the line nPrintln(5...


Q: Give two example computer applications for which connection-oriented service is appropriate. Give tw...

A: Two example computer applications for which connection-oriented service is appropriate:-Connection-o...


Q: Don't really know how to start solving this problem.

A: Using 4 bit counter we can implement a modulo 12 synchronous counter by ensuring that all the flip f...


Q: Descrube the method that can be used to attack text based CAPTCHA

A: Method used to attack text based captchaThe text based captcha breaking is based on segmentation and...


Q: As SOA service vendors are likely to be consolidated over time, an IT utility will emerge. In that s...

A: Success factors:The success factors of service enterprises depending on IT utility are as follows:Bu...


Q: How Technology can help to develop more effective policy?  (Information technology in Global Economy...

A: Information technology:Information technology(IT) has become a very important part of every business...


Q: Consider the UDP header 12 03 00 OF 00 1E A3 10. What is the total length of theUDP?

A: Consider the given:The given User Datagram Protocol header is “12 03 00 0F 00 1E A3 10”.


Q: I need help figuring out how to summarize the content and format of a written technical report.

A: While we are writing a technical report we need to figure out the following points.The title page of...