Write a program in java to take input as age if it is less than 18 generate arithmetic exception otherwise print “Welcome to the group of votes”?

class Votes

{

      public static void main(String arg[])

      {

            try

            {

                  int age=Integer.parseInt(arg[0]);

                  if(age<18)

                        throw new ArithmeticException("Invalid Age Exception");

                  else

                        System.out.println("Welcome To The Group Of Votes");

            }

            catch(Exception e)

            {

                  System.out.println(e);

            }

            System.out.println("Normal Flow");

      }

}

Welcome To The Group Of Votes.PNG

, , , , , , ,

Leave a Reply