0% found this document useful (0 votes)
22 views

Public Class Public Static Int Int Int For Int: Out Out

This document contains code that demonstrates the use of varargs in Java. The VarargsExample class contains two static methods, multiply() and multiply2(), that both multiply the numbers in an array or varargs parameter together and return the result. The TestVarargs class calls both methods, passing an array to multiply() and individual arguments to multiply2(), to show how varargs allows a method to accept an indefinite number of arguments of a particular type.

Uploaded by

Abdul Gafur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Public Class Public Static Int Int Int For Int: Out Out

This document contains code that demonstrates the use of varargs in Java. The VarargsExample class contains two static methods, multiply() and multiply2(), that both multiply the numbers in an array or varargs parameter together and return the result. The TestVarargs class calls both methods, passing an array to multiply() and individual arguments to multiply2(), to show how varargs allows a method to accept an indefinite number of arguments of a particular type.

Uploaded by

Abdul Gafur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

public class VarargsExample {

public static int multiply(int[] numbers){


int result = 1;

for(int number: numbers){
result= result*number;
}

return result;
}

public static int multiply2(int...numbers){
int result = 1;

for(int number: numbers){
result= result*number;
}

return result;
}

}



==
public class TestVarargs {

public static void main(String[] args) {

System.out.println(VarargsExample.multiply(new int[]{2,2,8}));
System.out.println(VarargsExample.multiply2(4,5,6));
}

}

You might also like