zoukankan      html  css  js  c++  java
  • 异常处理动手动脑

    结果:

    ArrayIndexOutOfBoundsException/内层try-catch

    发生ArithmeticException

    结果:

    ArrayIndexOutOfBoundsException/外层try-catch

    不一定,程序可能会在finally语句前结束。

    源代码:

    import java.util.Scanner;
    public class Test 
    {
        public static void main(String[] args)	
        {
        	Scanner input=new Scanner(System.in);
        	int score;
        	int receiveScore;
        	System.out.println("输入一个整数:");
    
        		if(input.hasNextInt())
        			
                    {
        			    receiveScore=input.nextInt();
        			    if(receiveScore<=100)
        			    {
        			    	score=receiveScore;   			    	
        			    }
        			    else
        			    {
        			    	System.out.println("错误:输入分数大于100");
        			    	score=101;
        			    }
        			       
                    }
        	    else   	
        	    {
        	    	 System.out.println("错误:输入的是非整数"); 
        	    	 score=101;
        	    }
        		     	
        		
        	
        	if(score<=59)
        	{
        		System.out.println("不及格");
        	}
        	else if(score<=69)
        	{
        		System.out.println("及格");
        	}
        	else if(score<=79)
        	{
        		System.out.println("中");
        	}
        	else if(score<=89)
        	{
        		System.out.println("良");
        	}
        	else if(score<=100)
        	{
        		System.out.println("优");
        	}
        }
    }

    运行结果:

      

  • 相关阅读:
    DBUtils温习2
    DBUtils温习1
    C3P0连接池温习1
    JDBC复习2
    JDBC复习1
    Spring的AOP基于AspectJ的注解方式开发3
    Spring的AOP基于AspectJ的注解方式开发2
    Spring的AOP基于AspectJ的注解方式开发1
    高血压认知3
    pandas cookbook
  • 原文地址:https://www.cnblogs.com/ssyh/p/7845538.html
Copyright © 2011-2022 走看看