Java Format: Unbound (saleable)
Java Format: Unbound (saleable)
8th Edition
ISBN: 9780134448398
Author: SAVITCH, Walter
Publisher: Prentice Hall
Expert Solution & Answer
Book Icon
Chapter 9.3, Problem 28STQ

Explanation of Solution

Given program segment:

The changed value is highlighted.

//Try block

try

{

    //Assign a value to the variable

    int n = -7;

    //Checking if value is greater than 0

    if(n > 0)

        //Throwing a predefined exception

        throw new Exception();

    //Checking if n is lesser than 0

    else if (n < 0)

        //Throwing user-defined exception

        throw new NegativeNumberException();

    //Else

    else

        //Print Hello

        System.out.println("Hello!");

}

//Catch the user-defined exception

catch (NegativeNumberException e)

{

    //Print the message

    System...

Blurred answer
Students have asked these similar questions
What is the result of the expression: ( ! ( ! ( x >= y ) || ! ( x != z ) ), using the following values; x = 8, y = -6, and z= 1?  True or False
my answer is incorrect so which of the choices is correct?
Answer correctly and properly this time else will give downvote as i give before

Chapter 9 Solutions

Java Format: Unbound (saleable)

Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr