Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package integerarrayexceptions;
- import java.util.Scanner;
- import java.util.InputMismatchException;
- public class IntegerArrayExceptions {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int numbers[] = new int[10];
- try{
- System.out.print("Please enter 10 integers to store in an array and then press enter: ");
- for(int index = 0; index < numbers.length; index++)
- numbers[index] = input.nextInt();
- if(numbers.length==10){ //method doesnt work properly if you input over 10 integers, only if you input less
- System.out.print("Thanks for entering 10 integers. Now input an integer to check: ");
- int compare = input.nextInt();
- if(numbers[index] == compare){
- System.out.print(compare);
- }
- }
- }
- catch (InputMismatchException MismatchException)
- {
- System.out.print("One or more values entered is not an integer.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement