import java.util.*; public class Retrieval { float[] numbers={3.8f, 1.2f, 22.0f, 19f, 0.01f, 19.24f, 5.28f}; public void doTheThing() { Scanner input=new Scanner(System.in); int choice=-1; System.out.println("Which value do you want? (0..6)"); System.out.println("(Negative to stop)"); do { try { choice=input.nextInt(); System.out.println( (choice>=0)? "Value at ["+choice+"]: "+numbers[choice]: "Byeee!" ); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Invalid input: please stay within 0..6"); } catch (InputMismatchException ime) { System.out.println("We encountered an issue we could not resolve."); System.out.println("Please try to be less irritating in the future."); } } while (choice>=0); input.close(); } public static void main(String[] args){new Retrieval().doTheThing();} }