Create a method that accept varargs in Java
public class Main {
public static void main(String[] args) {
printParams(1, 2, 3);
printParams(10, 20, 30, 40, 50);
printParams(100, 200, 300, 400, 500);
}
public static void printParams(int... numbers) {
for (int number : numbers) {
System.out.println(number + ", ");
}
}
}
Related examples in the same category