• 第六次实训作业


    1. 编写一个类ExceptionTest,在main方法中使用try-catch-finally语句结构实现:

    ²  在try语句块中,编写两个数相除操作,相除的两个操作数要求程序运行时用户输入;

    ²  在catch语句块中,捕获被0除所产生的异常,并输出异常信息;

    在finally语句块中,输出一条语句

    package practice5;
    import java.util.Scanner;
    public class ExceptionTest {

        
        public static void main(String[] args) {
               Scanner input=new Scanner(System.in);
               System.out.println("请输入除数:");
               int o1=input.nextInt();
               System.out.println("请输入被除数:");
               int o2=input.nextInt();
               int result=0;
               try{
               result=o2/o1;
              }catch(ArithmeticException e){
                  e.printStackTrace();
                  System.out.println("异常");
               }finally{
         
               }
               System.out.println(result);
        }

    }

    1. 编写一个应用程序,要求从键盘输入一个double型的圆的半径,计算并输出其面积。测试当输入的数据不是double型数据(如字符串“abc”)会产生什么结果,怎样处理。

    package practice5;
    import java.util.InputMismatchException;
    import java.util.Scanner;
    public class yuan {
        static double p=3.14;
        public static void main(String[] args) {
            Scanner input=new Scanner(System.in);
            System.out.println("请输入圆的半径:");
            double s=0;
            double r=0;
            try{
             r=input.nextDouble();
            }catch(InputMismatchException e){
                 e.printStackTrace();
                 System.out.println("非数字异常");
                 }
            catch(NegativeArraySizeException e){
                 e.printStackTrace();
                 System.out.println("负数异常");
            }
            s=p*r*r;
            System.out.println(s);
        }

    }

  • 相关阅读:
    SQL注入绕过——主要是magic_quotes_gpc, is_int(只能跑路,无注入点),以及关键字绕过,WAF绕过
    小葵多功能转换工具——编解码绕过,TODO
    load_file() 常用敏感信息
    crontab 结合 thinkphp3.2
    Docker 小型电脑
    Linux 查找大目录
    phpmyadmin 连接远程数据库
    git 变更 地址
    showdoc可以导出
    showdoc搭建
  • 原文地址:https://www.cnblogs.com/ccqblog1127/p/10831031.html
Copyright © 2020-2023  润新知