WAP to accept 5 command line arguments and then raise custom exception if any argument is not from the list
(“BCA”,”MCA”,”BBA”,”MBA”,”OTHER”).
class CE extends Exception
{
public CE(String s)
{
super(s);
}
}
class AP17
{
public static void main(String args[])
{
String my_arr[]={"BCA","MCA","BBA","MBA","OTHER"};
int i,j,flag=0;
try
{
for(i=0;i<5;i++)
{
flag=0;
System.out.println(args[i]);
for(j=0;j<5;j++)
{
if(args[i].equals(my_arr[j]))
{
flag=1;
break;
}
}
if(flag==0)
throw new CE("=> Not found...");
}
System.out.println("Everything is ok");
}
catch(CE ex)
{
System.out.println(ex.getMessage());
}
}
}
Leave a Reply