• 动手动脑


    动手动脑1

    程序运行结果:

    ArrayIndexOutOfBoundsException/内层try-catch发生ArithmticException

    动手动脑2

    运行结果:

    ArrayIndexOutOfBoundsException/外层try-catch

    finally语句块一定会执行吗?

    public class EmbededFinally 

    {  public static void main(String args[]) {

      int result;

    try {System.out.println("in Level 1")

     try 

    { System.out.println("in Level 2);

     try {

                       

                         System.out.println("in Level 3");

                          

                         result=100/0;  //Level 3                

                    } 

                    

                    catch (Exception e) {

                        

                        System.out.println("Level 3:" + e.getClass().toString());

                    

                    }

                    

                    

                    finally {

                        

                        System.out.println("In Level 3 finally");

                    

                    }

                    

                   

                    // result=100/0;  //Level 2

                

                    }

                

                catch (Exception e) {

                   

                     System.out.println("Level 2:" + e.getClass().toString());

               

                 }

                 finally {

                    

                    System.out.println("In Level 2 finally");

               

                 }

                 

                // result = 100 / 0;  //level 1        

            } 

            

            catch (Exception e) {

                

                System.out.println("Level 1:" + e.getClass().toString());

            

            }

            

            finally {

               

    .             System.out.println("In Level 1 finally");

            

            }

        

        }

     

    结果:

    in Level 1

    in Level 2

    in Level 3

    Level 3:class java.lang.ArithmeticException

    In Level 3 finally

    In Level 2 finally

    In Level 1 finally

     import javax.swing.*;

    public class ChengJi0 {

           public static void main(String[] args)

           {

           int a=0;

            

           

          

            

            try{

            String ing = JOptionPane.showInputDialog("输入你的成绩");

                

            a = Integer.parseInt(ing); 

                

            }

            catch(Exception e)

        {

            JOptionPane.showMessageDialog(null,"输入不正确,请重新输入","学生成绩",javax.swing.JOptionPane.INFORMATION_MESSAGE);

        System.exit(0);

           

            }

            if(a>=0&&a<60)

            {

            JOptionPane.showMessageDialog(null,"不及格","学生成绩",javax.swing.JOptionPane.INFORMATION_MESSAGE);

            }

            

            if(a>=60&&a<70)

            {

            JOptionPane.showMessageDialog(null,"及格","学生成绩",javax.swing.JOptionPane.INFORMATION_MESSAGE);

            

            }

            if(a>=70&&a<80)

            {

            JOptionPane.showMessageDialog(null,"","学生成绩",javax.swing.JOptionPane.INFORMATION_MESSAGE);

            

            }

            if(a>=80&&a<90)

            {

            JOptionPane.showMessageDialog(null,"","学生成绩",javax.swing.JOptionPane.INFORMATION_MESSAGE);

            

            }

            

             if(a>=90&&a<=100)

            {

            JOptionPane.showMessageDialog(null,"","学生成绩",javax.swing.JOptionPane.INFORMATION_MESSAGE);

            }

            if(a>100||a<0)

            {

            JOptionPane.showMessageDialog(null,"输入不正确","学生成绩",javax.swing.JOptionPane.INFORMATION_MESSAGE);

                

            

            }

            

      

                

                

        }  

            }

           

     

  • 相关阅读:
    opencv_图像的色彩空間cvtColor(HSV、HSL、HSB )及相关色彩学
    ASCII码字符对照表
    机器学习_logistic回归和梯度下降
    mysql 安装异常:this application requires .NET Framework(尚未安装.NET Framework 4.5 原因是:指定)
    面向对象的基本原则----
    面试题:“你能不能谈谈,java GC是在什么时候,对什么东西,做了什么事情?”
    String 解析--创建对象存储分析
    <cache> does not allow attribute "maxBytesLocalDisk
    Your 30-day trial of MyEclipse has expired 解决方案
    svn: E175002: java.lang.RuntimeException: Could not generate DH keypair svn: E175002: OPTIONS request failed on '/svn/ERPHR/HR_633'
  • 原文地址:https://www.cnblogs.com/lipengpengpeng/p/4966275.html
Copyright © 2020-2023  润新知