Lab1 -; i--; } }...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.InputMismatchException; import java.util.Scanner; public class Lab1 { public static <T> boolean search(T[] arr, T target){ for(int i = 0; i < arr.length; i++){ if (arr[i] == target) return true; } return false; } public static <T> void print(T[] arr){ for(int i = 0; i < arr.length; i++){ System.out.println(arr[i]); } } public static void main(String[] args){ Integer[] testArray = new Integer[10]; Scanner in = new Scanner(; String yesNo = "y"; System.out.println("Enter 10 Values:"); for(int i = 0; i<10; i++){ try{ testArray[i] = in.nextInt(); } catch(InputMismatchException e){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview:; i--; } } while(yesNo.equals(&quot;y&quot;)){ System.out.println(&quot;Enter a value to search for:&quot;); try{ System.out.println(,in.nextInt())); } catch(InputMismatchException e){; System.out.println(&quot;Enter a valid value:&quot;); } System.out.println(&quot;Would you like to search for another value? (y or n):&quot;); yesNo =; while(!yesNo.equals(&quot;y&quot;) &amp;&amp; !yesNo.equals(&quot;n&quot;)){ System.out.println(&quot;Input not correct, enter 'y' or 'n'&quot;); yesNo =; } } Lab1.print(testArray); } }...
View Full Document

This lab report was uploaded on 04/21/2008 for the course CSC 103 taught by Professor Franklin during the Spring '07 term at Cal Poly.

Ask a homework question - tutors are online