Advertisement
tampurus

47 Exception if n ( 0>n>100) throw exception

May 29th, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.*;
  2. public class Main
  3. {
  4.     public static void main(String[] args) {
  5.         Scanner fn = new Scanner(System.in);
  6.         System.out.println("Enter a number ");
  7.         int n = fn.nextInt();
  8.        
  9.         if(n<0 || n>100){
  10.             throw new ArithmeticException("Number is smaller than 0 and greater than 100");
  11.         }
  12.         else {
  13.             System.out.println("Your input is fine");
  14.         }
  15.     }
  16. }
  17. /*
  18. Enter a number
  19. -1
  20. Exception in thread "main" java.lang.ArithmeticException: Number is smaller than 0 and greater than 100
  21.         at Main.main(Main.java:10)
  22. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement