一次打印一个链表节点(Java)



关于如何一次打印一个条目的任何想法,例如按enter键显示下一个条目。这是printLink方法:

//Print Link data
    public void printLink()
    {
            System.out.println("") ;
            System.out.print("Book Name: " + getBookName() + "n" + "Book's Author: " + getBookAuthor() + "n" + "Year Published: " + getPublicYear() + "n" + "ISBN: " + getIsbn() +"n");
            System.out.println("") ;
    }

这是printList方法:

//Prints list data
    public void printList()
    {
            Link currentLink = first;
            while(currentLink != null) {
                    currentLink.printLink();
                    currentLink = currentLink.nextLink;
            }
            System.out.println("");
    }

每次打印后等待用户输入:

    public void printList()
    {
            Scanner scan = new Scanner(System.in);
            Link currentLink = first;
            while(currentLink != null) {
                    currentLink.printLink();
                    currentLink = currentLink.nextLink;
                    scan.next();
            }
            System.out.println("");
    }

相关内容

  • 没有找到相关文章