Computer Science, asked by khushikhurana0905, 6 months ago

write a Program in java to input age of the student and check if he is eligible for temporary driving licence​

Answers

Answered by BadBabyGirl
2

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~


khushikhurana0905: this is not right
khushikhurana0905: but thank you for the concern
BadBabyGirl: i am sorry_But i got this from goog.le_
BadBabyGirl: all fine
khushikhurana0905: Ohh... thanks
Answered by atrs7391
2

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");

       }

   }

}


khushikhurana0905: thank you
Similar questions