document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * Contoh Class Try Catch
  3.  *
  4.  * @author Muhammad Bagus Istighfar
  5.  * @version (23 Desember 2020)
  6.  */
  7.  
  8. import java.util.Scanner;
  9. public class TryCatch
  10. {
  11.     public static void main (String[] args){
  12.         boolean flag = true;
  13.  
  14.         while (flag){
  15.             try{
  16.             /*Pernyataan yang bisa mengakibatkan Exception lebih
  17.             tepatnya ArithemticException*/
  18.             Scanner input = new Scanner (System.in);
  19.  
  20.             System.out.println ("angka = ");
  21.             int angka = input.nextInt ();
  22.             System.out.println ("pembagi = ");
  23.             int pembagi = input.nextInt ();
  24.             int hasil = angka/pembagi;
  25.             System.out.println ("hasil = " +hasil);
  26.  
  27.             flag = false;
  28.             }
  29.  
  30.             catch(Exception e){
  31.             System.out.println ("Bilangan tidak bisa dibagi 0");
  32.             continue;
  33.             }
  34.         }
  35.     }
  36. }
  37.  
  38.  
');