Vikhyath_11

4

Jul 28th, 2024
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. package exceptions;
  2. import java.util.*;
  3.  
  4. public class Exceptions {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. int a,b,div;
  8. System.out.println("Input 2 numbers");
  9. a=sc.nextInt();
  10. b=sc.nextInt();
  11. try{
  12. div=a/b;
  13. System.out.println(div);
  14. }
  15. catch(ArithmeticException e){
  16. System.out.println("Exception Caught : Divide by Zero: "+e);
  17. }
  18.  
  19. int arr[]={1,2,3,4,5};
  20. try{
  21. System.out.println("fifth element is " + arr[5]);
  22. }
  23. catch(ArrayIndexOutOfBoundsException e1){
  24. System.out.println("Out of Bounds :" + e1);
  25. }
  26. }
  27.  
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment