Knowee
Questions
Features
Study Tools

1.Data Type Exception Get an integer input, If the input is 1, Throw an Integer exception. If the input is 2, Throw a Character exception. If the input is 3, Throw a double exception. Input Format The input consists of an integer. Output Format The output prints the corresponding exception. Refer sample output for formatting exception. Sample Input 1 Sample Output Integer exception caught. Sample Input 2 Sample Output Character exception caught. Sample Input 3 Sample Output Double exception caught.

Question

1.Data Type Exception

Get an integer input,

If the input is 1, Throw an Integer exception.

If the input is 2, Throw a Character exception.

If the input is 3, Throw a double exception.

Input Format

The input consists of an integer.

Output Format

The output prints the corresponding exception.

Refer sample output for formatting exception.

Sample Input

1

Sample Output

Integer exception caught.

Sample Input

2

Sample Output

Character exception caught.

Sample Input

3

Sample Output

Double exception caught.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This problem can be solved using a simple if-else statement in any programming language. Here is a Python solution:

# Get the input
num = int(input())

# Check the input and throw the corresponding exception
if num == 1:
    print("Integer exception caught.")
elif num == 2:
    print("Character exception caught.")
elif num == 3:
    print("Double exception caught.")
else:
    print("Invalid input.")

This program first takes an integer input from the user. Then it checks the value of the input. If the input is 1, it prints "Integer exception caught.". If the input is 2, it prints "Character exception caught.". If the input is 3, it prints "Double exception caught.". If the input is anything else, it prints "Invalid input.".

This problem has been solved

Similar Questions

Describe two types of exceptions in the context of java programming

Explain. Exception handling with example.

e a Java program for the above with proper exception handling.Input-Output Form 1:

Explain the following terms w.r.t exception handling i) Try ii) catch iii) throw iv) fina

exception handling in java

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.