简体   繁体   中英

Print linked list nodes one entry at a time (Java)

Any idea on how to print one entry at a time eg Press enter to show next entry. This is the printLink method:

//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("") ;
    }

This is the printList method:

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

Wait for a user input after each print:

    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("");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM