Source code for CheckIntArrayExample1.java:

public class CheckIntArrayExample1
{
	public int checkIntArrays(int[] inputArray)
	{
		int aryIndex;
		int arySize = inputArray.length;
		for(aryIndex = 0; aryIndex < arySize; aryIndex++)
		{
			if(inputArray[aryIndex] > 20)
			{
				return(aryIndex);
			}  
		}
		return(-1);
	}
	
	public void testArray(int array[])
	{
		// Print the array then test it.
		System.out.print("Index of value > 20 for array {");
		boolean firstTime = true;
		for (int i=0; i

Output from CheckIntArrayExample1.java:

Index of value > 20 for array { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }:-1 Index of value > 20 for array { 5, 10, 15, 20, 25 }:4 Index of value > 20 for array { 20, 40, 60, 80, 100 }:1

--- Output Ends ---

NOTE:

You are reading previously generated output. You are not currently running the CheckIntArrayExample1 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