file3.java

来自「学习java编程的好程序」· Java 代码 · 共 59 行

JAVA
59
字号
import java.io.*
import java.awt.*;
import java.awt.event.*
import java.applet.Applet;
public class file3
{
    public class DivideByZeroException extends ArithmeticException
    {
        public DivideByZeroException()
        {
            super(“Attempted to divide by zero”);
        }
    }
public class DivideByZeroTest extends Applet
{
    Label prompt1,prompt2;
    TextField input1,input2;
    Int number1,number2;
    Double result 
    public void init()
    {
        prompt1=new Label (“输入被除数”);
        input1=new TextField(10);
        prompt2=new Label (“输入除数并按下回车”);
        input2=new TextField(10);
        add (prompt1);
        add (input1);
        add (prompt2);
        add (input2);
    }
    public boolean action (Event event,Object obeject )
    {
        if (event.target==input2)
        {
            number1=Integer.parseInt(input1.getText());
            input1.setText(“”);
            number2=Integer.parseInt(input2.getText()) 
            input2.setText(“”); 
            try
            {
                result=quotient(number1,number2);
                showStatus(number1+”/”+number2+”=”+Double.toString(result));
            }
            catch(DivideByZeroException exception)
            {
                showStatus(exception.toString());
            }
        }
        return true;
    }
    public double quotient(int numerator,int denominator)throws DivideByZeroException
    {
        if (denominator==0) 
        throw new DivideByZeroException ();
        else (denominator!=0)
        return(double) numerator;
    } 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?