khirulnizam

HandlingExceptions.java

Jul 16th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. package kerul.net;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class HandlingExceptions {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         Scanner io = new Scanner(System.in);
  10.         int n1, n2, hasil;
  11.         try{
  12.             System.out.println("Enter 1st number");
  13.             n1=io.nextInt();
  14.             System.out.println("Enter 2nd number");
  15.             n2=io.nextInt();
  16.             hasil=n1+n2;
  17.             System.out.println("Hasil "+hasil);
  18.         }catch(NumberFormatException ex){
  19.             System.out.println(ex);
  20.         }catch(IllegalArgumentException ex){
  21.             System.out.println(ex);
  22.         }
  23.        
  24.        
  25.         System.out.println("OK, proceed to next process");
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment