Java Reference
In-Depth Information
double balance;
try
{
System.out.print("Enter balance: ");
balance = console.nextDouble();
System.out.println();
if (balance < 1000.00)
throw new Exception("Balance must be greater than 1000.00");
System.out.println("Leaving try block.");
}
catch (Exception obj)
{
System.out.println("Balance must be greater than 1000.00");
}
a. In this code, identify the try block.
b. In this code, identify the catch block.
c. In this code, identify the catch block parameter and its type.
d. In this code, identify the throw statement.
7. Assume the code given in Exercise 6.
a. What is the output if the input is 1200 ?
b. What is the output if the input is 975 ?
c. What is the output if the input is -2000 ?
8. Consider the following Java code:
int lowerLimit;
...
try
{
System.out.println("Entering the try block.");
if (lowerLimit < 100)
throw new Exception("Lower limit violation.");
System.out.println("Exiting the try block.");
}
catch (Exception e)
{
System.out.println("Exception: " + e.getMessage());
}
System.out.println("After the catch block");
What is the output if:
a. The value of lowerLimit is 50 ?
b. The value of lowerLimit is 150 ?
Search WWH ::




Custom Search