java考虑了这个问题。当遇到除数是0时,它并不抛出问题,而是得到无穷大的结果。

解决方案 »

  1.   

    不知道你的输入结果是怎么出来的,我在JB下编译后结果为:
    java.lang.ArrayIndexOutOfBoundsException: 0 at Untitled1.main(Untitled1.java:8)数组下标越界当然第二个异常抓不到了..
      

  2.   

    这个是我学JAVA异常时做的一个例题(JAVA程序设计教程)import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class DivideByZeroTest extends JFrame implements ActionListener{

    private JTextField inputField1,inputField2,outputField;
    private int number1,number2,result;

    public DivideByZeroTest()
    {
    super( "Divide By Zero Test" );

    Container container = getContentPane();
    container.setLayout( new GridLayout( 3,2 ) );

    container.add( new JLabel( "Enter numberator",SwingConstants.RIGHT ) );
    inputField1 = new JTextField();
    container.add( inputField1 );

    container.add( new JLabel( "Enter denominator and press Enter",
    SwingConstants.RIGHT ) );
    inputField2 = new JTextField();
    container.add( inputField2 );
    inputField2.addActionListener( this );

    container.add( new JLabel( "RESULT",SwingConstants.RIGHT ) );
    outputField = new JTextField();
    container.add( outputField );

    setSize( 425,100 );
    setVisible( true );
    }

    public void actionPerformed( ActionEvent event )
    {
    outputField.setText( "" );

    try{
    number1 = Integer.parseInt( inputField1.getText() );
    number2 = Integer.parseInt( inputField2.getText() );

    result = quotient( number1,number2 );
    outputField.setText( String.valueOf( result ) );
    }

    catch( NumberFormatException numberFormatException ){
    JOptionPane.showMessageDialog( this,"You must enter two integers",
    "Invalid Number Format",JOptionPane.ERROR_MESSAGE );
    }

    catch( ArithmeticException arithmeticException ){
    JOptionPane.showMessageDialog( this,arithmeticException.toString(),
    "Arithmetic Exception",JOptionPane.ERROR_MESSAGE );
    }
    }

    public int quotient( int numerator,int denominator )
    throws ArithmeticException
    {
    return numerator / denominator;
    }

    public static void main( String args[] )
    {
    DivideByZeroTest application = new DivideByZeroTest();
    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }
    }
      

  3.   

    当x,y 都声明为int 型时,才会抛出除0异常.
      

  4.   

    因该是double的问题,如果是int x = 9/0;是会出异常的!
      

  5.   

    你直接用个Exception类看看它所有的输出里面有没有。
      

  6.   

    有道理  E_Ball(亚森罗宾)运行时没输入参数把?
      

  7.   

    同意 wavewoo(飞天红猪侠) 的
      

  8.   

    同意:Apollo47(阿波罗) 。这里这是有这个细节要大家注意的。