Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Wednesday, 20 May 2015

Write a java program to throw a exception (checked) for an employee details. If an employee name is a number, a name exception must be thrown. If an employee age is greater than 50, an age exception must be thrown. or else an object must be created for the entered employee details

import java.io.*;
import java.util.*;
class Numx
{
public static void main(String args[])
 {
String name;
int age;
System.out.println("-----ENTER EMPLOYEE DETAILS-----");
System.out.println("Enter Name and Age:");
Scanner in=new Scanner(System.in);

try
{
if(!(in.nextLine().matches("[a-zA-Z]+")))
{throw new IOException();}

age=in.nextInt();
if(age>50)
{
System.out.println("Age greater than 50 Exception");
throw new Exception();
}

Numx x=new Numx();
System.out.println("-----Object Created-----");
}

catch(Exception e)
{
System.out.println("Exception");
}
}
}

2 comments:

  1. I have been searching to find a comfort or effective procedure to complete this process and I think this is the most suitable way to do it effectively.
    jantakhoj delhi

    ReplyDelete