MIT-Curricular/OOP/Java/Lab/Week10/numberformatexception.java

18 lines
514 B
Java
Raw Normal View History

2024-10-14 02:40:51 +05:30
import java.util.*;
public class numberformatexception {
public static void main(String[] args) {
int a;
Scanner in=new Scanner(System.in);
System.out.print("Input:");
try{
a=Integer.parseInt(in.nextLine());
System.out.println("Number entered is "+a);
}
catch(NumberFormatException e)//As NumberFormatException is typecasting error
{
System.out.println("Error:"+e.toString());
}
}
}