java-day13

第十三天

1,异常和错误

2,异常分类:2

3,常见异常:1/0    a[1]   "123a"   null

4,体系架构:Throwable : Error   Exception

5,异常处理:try{}catch(){}finally{}

6,没有谁,多个catch

7,final   finally  finalize

8,抛出异常throw   throws

   throws:抛出方法异常

   throw:方法内部抛出异常

9,自定义异常

10,练习题

 

 

1,基本概念:ADT  表   链表  栈  队列

2,数组:优点:查找快  缺点:删除,插入效率低,存储连续空间

   链表:优点:删除,插入效率高 存储零散空间  缺点:查找慢

3,链表:单向链表   双端链表   双向链表(前驱,后继)

4,优先级队列:

5,后缀表达式

 

A

public class A {

    private int[] a;

    private int size;

    public int get(){

        return a[0];

    }

    public void add(int aa){

       a[size++] = aa;

    }

}

 

Node

public class Node {

    public Node pre;

    public Object obj;

    public Node next;

}

 

CjbnwfException extends RuntimeException

public class CjbnwfException extends RuntimeException{

    public CjbnwfException(){}

    public CjbnwfException(String message){super(message);}

 

}

 

 

Test

import java.util.Scanner;

public class Test {

    private static void abc() throws Exception{

        //try{

            System.out.println(1/0);

        //}catch (Exception e){

        //    e.printStackTrace();

        //}

    }

    private static void bcd(){

        int[] a = {1,2,3};

        //try{

            System.out.println(a[3]);

        //}catch (Exception e){

        //    e.printStackTrace();

        //}

    }

    private static void cde(){

        String s = "123a";

        //try{

           System.out.println(Integer.parseInt(s));

        //}catch (Exception e){

        //    e.printStackTrace();

        //}

    }

    private static void def() throws CjbnwfException{

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();

        if (a<0){

            throw new CjbnwfException("成绩不能是负数");

        }

    }

    public static void main(String[] args){

        /*try {

            abc();

        } catch (Exception e) {

            e.printStackTrace();

        }

 

        try{

            bcd();

        }catch (Exception e){

            e.printStackTrace();

        }

        try{

            cde();

        }catch (Exception e){

            e.printStackTrace();

        }

        try {

            def();

        } catch (CjbnwfException e) {

            e.printStackTrace();

        }*/

        /*int a=9;

        int b = 0;

        if(b==0){

            throw new ArithmeticException();

        }*/

        /*Scanner sc = new Scanner(System.in);

        int[] a = new int[5];

        int count = 0;

        for (int i=0;i<5;i++){

            try {

                a[i] = sc.nextInt();

                count++;

            }catch (Exception e){

                System.out.println("qing shuru zhengshu");

                sc.next();

            }

        }

        if (count<5){

            try{

                throw new Exception();

            }catch (Exception e){

                System.out.println("qing zhishaoshuruwugeshu");

            }

        }

*/

    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值