write a Program in java to input age of the student and check if he is eligible for temporary driving licence
Answers
Answer:
import java.util.Scanner;
class AgeException extends Exception {
public AgeException(String str) {
System.out.println(str);
}
}
public class AgeExcDemo {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter ur age :: ");
int age = s.nextInt();
try {
if(age < 18)
throw new AgeException("Invalid age");
else
System.out.println("Valid age");
}
catch (AgeException a) {
System.out.println(a);
}
}
}
Explanation:
Hope It Helped~
Have A Nice Day~
Answer:
I tried to keep it simple but if you want you can change class name, arguments etc. of your own. Hope this helps
Explanation:
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter student's age: ");
int a = sc.nextInt();
if (a>17){
System.out.println("Student is eligible for temporary driving licensee");
}
else{
System.out.println("Student is not eligible for temporary driving licensee");
}
}
}