HackerRank/JAVA
Java Exception Handling (Try-catch)
예쁜꽃이피었으면
2024. 1. 22. 16:31
https://www.hackerrank.com/challenges/java-exception-handling-try-catch/problem?isFullScreen=true
Java Exception Handling (Try-catch) | HackerRank
Use try-catch to test a block of code for errors.
www.hackerrank.com
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
try{
int x = sc.nextInt();
int y = sc.nextInt();
// System.out.println(x%y);
System.out.println(x/y);
}catch(InputMismatchException mi){
System.out.println("java.util.InputMismatchException");
}catch(ArithmeticException ari){
System.out.println("java.lang.ArithmeticException: / by zero");
}
}
}
반응형