谁能帮我改下这个JAVA的代码? 急 急 急

来源:百度知道 编辑:UC知道 时间:2024/06/23 22:39:48
class Test
{
public static void main(String args[])
{
String firstParam=null;
String secondParam=null;

try
{

firstParam=args[0];

secondParam=args[1];

int param1=Integer.parseInt(firstParam);
int param2=Integer.parseInt(secondParam);

int value=param1/param2;

System.out.println("value");
}
catch(Array Index Out Of Bounds Exception e)
{
System.out.println("错误消息:数组下标越界");
}
catch(Arithmetic Exception e)
{
System.out.println("错误消息:除数为零");
}
catch(Number Format Exception e)
{
System.out.println("错误消息:数据类型转换出错");
}
}
}

那个捕捉异常的异常名不能是分开写的,需要合起来写,还有输出value的值时不能加"",否则会打印出字符串value,而不是数值。改完后的代码
class TestDemo
{
public static void main(String args[])
{
String firstParam=null;
String secondParam=null;

try
{

firstParam=args[0];

secondParam=args[1];

int param1=Integer.parseInt(firstParam);
int param2=Integer.parseInt(secondParam);

int value=param1/param2;

if (args.length>2)
{
System.out.println("错误消息:数组下标越界");
}
else
System.out.println(value);
}
catch(ArithmeticException e)
{
System.out.println("错误消息:除数为零");
}
catch(NumberFormatException e)
{
System.out.println("错误消息:数据类型转换出错");
}
}
} 编译正常编译,执行时加上两个数即可,例如java Text 2 1

class Test {
public static void main(String args[]) {
String firstParam = null;