Page 628 - Introduction to Programming with Java: A Problem Solving Approach
P. 628

                594 Chapter 14 Exception Handling
19. Given a non-void method that contains no try and catch blocks. If the method throws an exception, we know that the JVM transfers the thrown exception back to the calling method. But does the JVM return a value (with a return statement) to the calling module?
Exercises
1. [after §14.3] Given the below program, what is the output if the user enters “one” in response to the prompt? /*************************************************************
 *
FantasyFootball.java
Dean & Dean
This prints out names of football players.
*************************************************************/
*
*
*
import java.util.Scanner;
import java.util.ArrayList;
public class FantasyFootball
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
       Apago PDF Enhancer
String indexStr;
int index = 0;
players.add("Peyton Manning");
players.add("Ladanian Tomlinson");
players.add("Reggie Bush");
System.out.print("Enter a number between 1 and 3: ");
indexStr = stdIn.nextLine();
try
{
ArrayList<String> players = new ArrayList<String>();
}
{
}
try
{
}
{
}
index = Integer.parseInt(indexStr);
System.out.println("Entered index OK.");
catch (NumberFormatException e)
System.out.println("Entered index wasn't an integer");
System.out.println(players.get(index - 1));
catch (IndexOutOfBoundsException e)
System.out.println(
"Can't access players[" + (index - 1) + "]");





















































   626   627   628   629   630