Try this code using varargs and pass any number of int values to test.
implementing a method that returns true if any argument is in the range
As per your question - returns true if either of them is in the range 10..20 inclusive.
public boolean s(int... a) {
for (int i : a) {
if (i > 9 && i < 21) {
return true;
}
}
return false;
}
--EDIT--
implementing a method that returns true if all argument is in the range
public static boolean s(int... a) {
for (int i : a) {
if (i < 10 || i > 20) {
return false;
}
}
return (a.length > 0);
}
--EDIT--
put a check if needed in the beginning of the method but I never suggest you to use it.
if (a.length != 2) {
throw new IllegalArgumentException("It accepts only two arguments");
}
--EDIT--
as per your requirement if you can't change the method signature that may come from an interface or super class.
public boolean s(int a, int b) {
int[] array = new int[] { a, b };
for (int i : array) {
if (i > 9 && i < 21) {
return true;
}
}
return false;
}