ArraySearch2

ArraySearch2 - import java.util.Scanner Fills an array and...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.Scanner; i // Fills an array, and searches for a particular value // Will print where it was found, if there / public class ArraySearch2 { public static void main(String[] args) { final int INTARRAY_LENGTH = 1000; int[] intArray = new int[INTARRAY_LENGTH]; int intArraySize = 0; Scanner in = new Scanner(System.in); //Call a method readData to fill the array; //returns the number of integers read intArraySize = readData(intArray); //print the array printArray( intArray, intArraySize); System.out.println( "What value are you searching for?" ); int searchNumber = in.nextInt(); //call the method to search in the array for the search number int position = searchArray(intArray, intArraySize, searchNumber); System.out.println( searchNumber + " was found in the array at " + position); } /** Reads data from the console into an array @param data the array to be filled @return the number of the items read into the array */ public static int readData(int[] data) { Scanner in= new Scanner(System.in);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/07/2010 for the course CS 201 taught by Professor Staff during the Spring '08 term at Iona.

Page1 / 2

ArraySearch2 - import java.util.Scanner Fills an array and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online