Attetion: 1.The name "DiviedByZero()" should be "DividedByZero()"; 2.The fatal Error: The constructors in any classes must have not return value, so the constructor "public void DiviedByZero()" should be "public void DividedByZero()"According to above all, the program should be:_____________________________________________________________________________ class DividedByZero extends ArithmeticException { public DividedByZero() { super("除以零所产生的例外"); } }public class ThrowTest { public static void main(String args[]) { System.out.println("divide(9,3)="+divide(9,3)); System.out.println("divide(7,0)="+divide(7,0)); }
public static int divide(int a,int b) { if (b!=0) return(a/b); else { throw new DividedByZero(); } }---------------------------------------------------------------------------
Attetion: 1.The name "DiviedByZero()" should be "DividedByZero()"; 2.The fatal Error: The constructors in any classes must have not return value, so the constructor "public void DiviedByZero()" should be "public DividedByZero()"According to above all, the program should be:_____________________________________________________________________________ class DividedByZero extends ArithmeticException { public DividedByZero() { super("除以零所产生的例外"); } }public class ThrowTest { public static void main(String args[]) { System.out.println("divide(9,3)="+divide(9,3)); System.out.println("divide(7,0)="+divide(7,0)); }public static int divide(int a,int b) { if (b!=0) return(a/b); else { throw new DividedByZero(); } }---------------------------------------------------------------------------
public SynTest() {... 改为 public Syntest() {...public void DiviedByZero() {... 改为 public DiviedByZero() {...public static int divide(int a,int b) {... 改为 public static int divide(int a,int b) throws DividedByZero {...
1.The name "DiviedByZero()" should be "DividedByZero()";
2.The fatal Error: The constructors in any classes must have not return value, so the constructor "public void DiviedByZero()" should be "public void DividedByZero()"According to above all, the program should be:_____________________________________________________________________________
class DividedByZero extends ArithmeticException
{
public DividedByZero()
{
super("除以零所产生的例外");
}
}public class ThrowTest
{
public static void main(String args[])
{
System.out.println("divide(9,3)="+divide(9,3));
System.out.println("divide(7,0)="+divide(7,0));
}
public static int divide(int a,int b)
{
if (b!=0)
return(a/b);
else
{
throw new DividedByZero();
}
}---------------------------------------------------------------------------
1.The name "DiviedByZero()" should be "DividedByZero()";
2.The fatal Error: The constructors in any classes must have not return value, so the constructor "public void DiviedByZero()" should be "public DividedByZero()"According to above all, the program should be:_____________________________________________________________________________
class DividedByZero extends ArithmeticException
{
public DividedByZero()
{
super("除以零所产生的例外");
}
}public class ThrowTest
{
public static void main(String args[])
{
System.out.println("divide(9,3)="+divide(9,3));
System.out.println("divide(7,0)="+divide(7,0));
}public static int divide(int a,int b)
{
if (b!=0)
return(a/b);
else
{
throw new DividedByZero();
}
}---------------------------------------------------------------------------
第二段 :public void DiviedByZero()该为public DiviedByZero()
改为
public Syntest() {...public void DiviedByZero() {...
改为
public DiviedByZero() {...public static int divide(int a,int b) {...
改为
public static int divide(int a,int b) throws DividedByZero {...