https://www.hackerrank.com/challenges/java-exception-handling-try-catch/problem?isFullScreen=true
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");
}
}
}
반응형
'HackerRank > JAVA' 카테고리의 다른 글
Java 1D Array (1) | 2024.01.22 |
---|---|
Java BigInteger (0) | 2024.01.22 |
Java Primality Test (0) | 2024.01.22 |
Valid Username Regular Expression (0) | 2024.01.19 |
[작성중]Java Regex 2 - Duplicate Words (0) | 2024.01.19 |