package ExceptionHandling;
import java.util.InputMismatchException;
import java.util.Scanner;
public class UserInputExceptions {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter the marks");
int Marks = getMarks();
if (Marks == 0){
}else{
System.out.println("Your have got " + Marks + " marks.");
}
}
public static int getMarks() {
try {
return input.nextInt();
} catch (InputMismatchException e)
{
System.out.println("You have enterd a wrong value:");
return 0;
}
}
}
No comments:
Post a Comment