Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * class untuk handling exception menggunakan try dan catch
- *
- * @author Dwinanda Bagoes Ansori
- * @version 29 Desember 2020
- */
- import java.util.Scanner;
- import java.util.InputMismatchException;
- public class TryCatch
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- boolean continu = true;
- do
- {
- try
- {
- System.out.print("Input Integer: ");
- int number = input.nextInt();
- //Menampilkan hasil
- System.out.println();
- System.out.println("Ur Number : " + number);
- continu = false;
- }
- catch(InputMismatchException ex)
- {
- System.out.println();
- System.out.println("Invalid Input!!! Input integer.");
- input.nextLine();
- }
- } while(continu);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment