public class CheckIntArrayExample2
{
public static final int VALID = 0;
public static final int NO_MATCH = 1;
public static final int MULTI_MATCH = 2;
public int checkIntArrays(int[] inputArray)
{
int aryIndex;
int matchCount = 0;
int arySize = inputArray.length;
for(aryIndex = 0; aryIndex < arySize; aryIndex++)
{
if(inputArray[aryIndex] > 20)
{
matchCount++;
}
}
if(matchCount == 1)
{
return(VALID);
}
if(matchCount == 0)
{
return(NO_MATCH);
}
return(MULTI_MATCH);
}
public void testArray(int array[])
{
// Print the array then test it.
System.out.print("Check array {");
boolean firstTime = true;
for (int i=0; i
Check array { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }:NO_MATCH Check array { 5, 10, 15, 20, 25 }:VALID Check array { 20, 40, 60, 80, 100 }:MULTI_MATCH
--- Output Ends ---
- javac CheckIntArrayExample2.java
- java CheckIntArrayExample2