public static void testArray(int[]a)
{
for(int i:a)
{
if(i==10)
{
System.out.println("Number 10 exists !");
}
}
}
I want to pass parameters to this method without creating variables. I want to call it like so:
testArray({5, 10, 15});
Is this possible?
testArray(new int[]{5, 10, 15});
public static void testArray(int ... a)
{
for(int i:a)
if(i==10)
System.out.println("Number 10 exists !");
}
testArray(5, 10, 15);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With