Variable Arguments

Java provides the varargs feature to allow methods to accept a variable number of arguments. This is useful when the exact number of inputs is unknown.

Syntax:

returnType methodName(dataType... variableName) {
    // Method body
}
Code Example
Output
Sum: 15
Sum: 30