Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Contoh Class Try Catch
- *
- * @author Albert Filip Silalahi
- * @version (1 Januari 2021)
- */
- import java.util.Scanner;
- public class TryCatch
- {
- public static void main (String[] args){
- boolean flag = true;
- while (flag){
- try{
- /*Pernyataan yang bisa mengakibatkan Exception lebih
- tepatnya ArithemticException*/
- Scanner input = new Scanner (System.in);
- System.out.println ("Masukkan angka ==>");
- int angka = input.nextInt ();
- System.out.println ("Masukkan pembagi ==>");
- int pembagi = input.nextInt ();
- int hasil = angka/pembagi;
- System.out.println ("HASIL ==> " +hasil);
- flag = false;
- }
- catch(Exception e){
- System.out.println ("ERROR");
- System.out.println ("Bilangan tidak bisa dibagi 0");
- continue;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment