Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class MyException extends Exception{}
- class InputTest{
- static Scanner sc = new Scanner(System.in);
- static public void main (String[] args){
- System.out.print("Enter your favorite number: ");
- try{
- if(!sc.hasNextBigInteger() && !sc.hasNextBigDecimal()){
- MyException e = new MyException();
- throw e;
- }
- else System.out.println("That's a cool number!");
- } catch(MyException e){
- System.out.println("That's not really a number!");
- }
- }
- }
- //Output:-
- //C:\Java>java InputTest
- //Enter your favorite number: 3.1415926535897932384626433832795028841971693993751058209
- //749445923078164062862089986280348253421170679
- //That's a cool number!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement