java程序设计与应用

学了Java程序设计与应用 一直想找刷题软件来练练 里面涉及到的封装 继承 接口 多线程什么的那些知识点 一直没有找到软件 一直在力扣上面刷题都是算法 我想练一下Java的那些基础知识在哪里可以刷题 有没有什么好的刷题网站啊

img

以下内容部分参考ChatGPT模型:


你可以尝试使用LeetCode(https://leetcode.com/%EF%BC%89%E5%92%8CHackerrank%EF%BC%88https://www.hackerrank.com/%EF%BC%89%E8%BF%99%E4%B8%A4%E4%B8%AA%E7%BD%91%E7%AB%99%E6%9D%A5%E7%BB%83%E4%B9%A0Java%E7%9A%84%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E3%80%82%E8%BF%99%E4%BA%9B%E7%BD%91%E7%AB%99%E6%8F%90%E4%BE%9B%E4%BA%86%E8%AE%B8%E5%A4%9AJava%E7%BC%96%E7%A8%8B%E9%97%AE%E9%A2%98%EF%BC%8C%E5%8C%85%E6%8B%AC%E5%B0%81%E8%A3%85%E3%80%81%E7%BB%A7%E6%89%BF%E3%80%81%E6%8E%A5%E5%8F%A3%E3%80%81%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%AD%89%E7%9F%A5%E8%AF%86%E7%82%B9%E3%80%82%E4%BD%A0%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E8%A7%A3%E5%86%B3%E8%BF%99%E4%BA%9B%E9%97%AE%E9%A2%98%E6%9D%A5%E6%8F%90%E9%AB%98%E4%BD%A0%E7%9A%84Java%E7%BC%96%E7%A8%8B%E6%8A%80%E8%83%BD%EF%BC%8C%E5%B9%B6%E5%8A%A0%E6%B7%B1%E5%AF%B9%E8%BF%99%E4%BA%9B%E7%9F%A5%E8%AF%86%E7%82%B9%E7%9A%84%E7%90%86%E8%A7%A3%E3%80%82

例如,下面是一个在LeetCode上的Java编程问题的示例,涉及到了封装和继承的知识点:

class MyLinkedList {
    private Node head;
    private int size;

    /** Initialize your data structure here. */
    public MyLinkedList() {
        head = null;
        size = 0;
    }
    
    /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */
    public int get(int index) {
        if (index < 0 || index >= size) {
            return -1;
        }
        Node curr = head;
        for (int i = 0; i < index; i++) {
            curr = curr.next;
        }
        return curr.val;
    }
    
    /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */
    public void addAtHead(int val) {
        Node newHead = new Node(val);
        newHead.next = head;
        head = newHead;
        size++;
    }
    
    /** Append a node of value val to the last element of the linked list. */
    public void addAtTail(int val) {
        if (head == null) {
            addAtHead(val);
            return;
        }
        Node curr = head;
        while (curr.next != null) {
            curr = curr.next;
        }
        curr.next = new Node(val);
        size++;
    }
    
    /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */
    public void addAtIndex(int index, int val) {
        if (index < 0 || index > size) {
            return;
        }
        if (index == 0) {
            addAtHead(val);
            return;
        }
        if (index == size) {
            addAtTail(val);
            return;
        }
        Node curr = head;
        for (int i = 0; i < index - 1; i++) {
            curr = curr.next;
        }
        Node newNode = new Node(val);
        newNode.next = curr.next;
        curr.next = newNode;
        size++;
    }
    
    /** Delete the index-th node in the linked list, if the index is valid. */
    public void deleteAtIndex(int index) {
        if (index < 0 || index >= size) {
            return;
        }
        if (index == 0) {
            head = head.next;
            size--;
            return;
        }
        Node curr = head;
        for (int i = 0; i < index - 1; i++) {
            curr = curr.next;
        }
        curr.next = curr.next.next;
        size--;
    }
    
    private class Node {
        int val;
        Node next;
        public Node(int val) {
            this.val = val;
            next = null;
        }
    }
}

这个问题要求你实现一个简单的链表数据结构,其中涉及到了封装和继承的知识点。你需要使用封装来隐藏链表的内部实现,同时使用继承来扩展链表的功能。通过解决这个问题,你可以加深对Java中封装和继承的理解,并提高你的Java编程技能。


如果我的建议对您有帮助、请点击采纳、祝您生活愉快