class Unitformatexception extends Exception
{
Unitformatexception(String s)
{
super("unit is not valid: " + s);
}
}
class Program9
{
public static void main(String args[])
{
int no;
String str;
try
{
no = Integer.parseInt(args[0]);
str = args[1];
if((str.equals("centimeter")) || (str.equals("meter")))
{
if(str.equals("centimeter"))
{
int m = no/100;
System.out.println("meter is : " + m);
}
else if(str.equals("meter"))
{
int cm = no*100;
System.out.println("centimeter is : " + cm);
}
else
throw new Unitformatexception(str);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println(e.getMessage());
}
catch(NumberFormatException n)
{
System.out.println(n.getMessage());
}
catch(ArithmeticException a)
{
System.out.println(a.getMessage());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
No comments:
Post a Comment