Question: This is in Java Using the same code, what gets printed if the user inputs fred? public int enterBetween (int x, int y) throws DoesNotFollowDirectionsException
This is in Java
Using the same code, what gets printed if the user inputs "fred"?
public int enterBetween (int x, int y) throws DoesNotFollowDirectionsException { int z; if (scan.hasNextInt()) { z = scan.nextInt(); if (z < x || z > y) throw new DoesNotFollowDirectionsException( "Value " + z + " not in range."); return z; } else throw new DoesNotFollowDirectionsException( "No integer to read."); } // Here is code from elsewhere that calls the enterBetween method: try { System.out.print("Enter an integer between 1 and 10: "); value = enterBetween(1,10); } catch (DoesNotFollowDirectionsException e) { System.out.println(e.getMessage()); System.exit(0); // ends the program }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
