zoukankan      html  css  js  c++  java
  • 第五次实训作业异常处理

    package dama;
    import java.util.Scanner;
    public class ExceptionTest {
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
            try {
                int x,y;
                Scanner scanner=new Scanner(System.in);
                x=scanner.nextInt();
                y=scanner.nextInt();
                int result=x/y;
                System.out.println(result);
                }
            catch(Exception e) {
                System.out.println("除数不为零");
            }
            finally {
                System.out.println("完成");
            }
        }

    package Input;
    import java.util.*;
    public class MismatchDemo {
         public static double Area(double r)
         {
                return r*r*Math.PI;
            }
         public static void main(String[] args) 
            {
                Scanner sc=new Scanner(System.in);
                try
                {
                    System.out.println("请输入半径:");
                    double r=sc.nextDouble();
                    System.out.println("此圆的面积为:"+Area(r));
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
                sc.close();
            }
    }
    
    

    
    }

     在此次学习中,感觉到异常的简单已经他的难。可以说这个异常处理需要你去深入的了解与探索才可能灵活运用。

  • 相关阅读:
    SpringBoot自定义HttpMessageConverter
    第一次使用Linux服务器所栽之坑
    入门Nginx
    HttpClient中的Timout
    SpringBoot启动
    SpringBoot注解
    百度2017春招笔试
    学习JUnit
    Mybatis中的@SelectKey注解
    PHP中MD5函数漏洞
  • 原文地址:https://www.cnblogs.com/quanzhilong/p/10872955.html
Copyright © 2011-2022 走看看