013-001-001

Exception Handling: Safe Division

Hard

Problem Description

In this problem, you will create a program that reads two integers, performs division safely with exception handling for division by zero and invalid input, and displays the result to standard output.

Problem Overview

Create a program that inputs two integers and performs division safely. Handle exceptions appropriately for division by zero and invalid input.

Input Format

Receive 2 lines of input:

  1. Dividend (integer)
  2. Divisor (integer)

Output Format

Normal case: [dividend] / [divisor] = [quotient]

Error cases:

  • Division by zero: Error: Division by zero
  • Invalid input: Error: Invalid input

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
10
2
Expected Output:
10 / 2 = 5
Normal case
Input:
15
4
Expected Output:
15 / 4 = 3

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 10 free executions remaining