{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab1 - in.next i while(yesNo.equals"y"...

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(System.in); 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: in.next(); i--; } } while(yesNo.equals("y")){ System.out.println("Enter a value to search for:"); try{ System.out.println(Lab1.search(testArray,in.nextInt())); } catch(InputMismatchException e){ in.next(); System.out.println("Enter a valid value:"); } System.out.println("Would you like to search for another value? (y or n):"); yesNo = in.next(); while(!yesNo.equals("y") && !yesNo.equals("n")){ System.out.println("Input not correct, enter 'y' or 'n'"); yesNo = in.next(); } } Lab1.print(testArray); } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online