could anyone please help me write a program which accepts an age and throws an exeception if(18>age>22).

Someone may be able to (note: I am not that person), though you will have to adhere to the forum policy of showing some effort yourself when asking about homework.

Post what you have so far and specific questions about which parts are giving you trouble.

first of all , welcome to daniweb :)

all the membesrs would love to help you out , but you should to show that you gave an effort to solving the problem too .. c'mon thats only fair :) if things didnt work out like that .. daniweb , or any forum for that matter , would soon become "solve my" :D

but anyways , as a 1st post bonus : heres a basic skeleton :

keep age as an "int"
use a "scanner" to read your input. syntax will be something like

import java.util.Scanner;
// code stuff
int age; 
//code stuff again
Scanner is = new Scanner(;// this will get input from console
age = is.nextInt();// take the integer and assign it to age

you should get this up running first , with a few print statements. when all that is good and running.. well solve the exception parts as well :)

have fun coding.:)