Source code for CheckIntArrayExample2.java:

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

Output from CheckIntArrayExample2.java:

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 ---

NOTE:

You are reading previously generated output. You are not currently running the CheckIntArrayExample2 application at the momement. You need to compile and run the source code first.

To run this program:


Authors: Kevin Chu and Eric Brower
Copyright 2000 Prentice Hall PTR