Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kerul.net;
- import java.util.Scanner;
- public class HandlingExceptions {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner io = new Scanner(System.in);
- int n1, n2, hasil;
- try{
- System.out.println("Enter 1st number");
- n1=io.nextInt();
- System.out.println("Enter 2nd number");
- n2=io.nextInt();
- hasil=n1+n2;
- System.out.println("Hasil "+hasil);
- }catch(NumberFormatException ex){
- System.out.println(ex);
- }catch(IllegalArgumentException ex){
- System.out.println(ex);
- }
- System.out.println("OK, proceed to next process");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment