Verwandte Themen

Ausgabe einer Hashmap?

Hallo zusammen

Ich habe eine Frage und zwar möchte ich folgende Hashmap in der console ausgeben jedoch habe ich Schwierigkeiten...

Der Code:

import java.util.HashMap;
import java.util.Scanner;

public class Passwordsaver {

    public static void main(String[] args) throws InterruptedException {

        // declare the hashmap
        HashMap<Integer, String> Password = new HashMap<>();
        boolean loopAgain = true;
        Scanner scan = new Scanner(System.in);

        // loop while user not entering no
        do {
            // ask for user input for id number
            System.out.print("Enter Page:");
            String page = scan.nextLine();

            // ask for user input which corresponds to student name
            System.out.print("Enter Password");
            String password = scan.nextLine();

            // add the key value pair from user input to the hashmap

            String oldVal = password + page;

            if (oldVal!=null) {
                System.out.println("The password for the page: " + page + " is "
                        + password + " and will be overwritten if entered again");
            }

            // ask user to check if another entry is required
            System.out.print("Enter another account (y/n)?");
            String answer = scan.nextLine();

            // condition to satisfy in order to loop again
            if (answer.equals("y") || answer.equals("Y")) {
                continue;
            } else {
                break; //stops
            }

        } while (loopAgain);
        scan.close();

        System.out.println("\n**********************************");
        System.out.println("The following students are in database");
        System.out.println("   account  "+ "      password");      
        for(int page:Password.keySet()){
            System.out.println("   "+page+"     "+Password.get(page));
        }
        System.out.println("\n**********************************");
    }

}

Es funktioniert alles bis auf den letzten Schritt bei while (loopAgain);

Da möchte ich das page sowie das password ausgeben...

Kann mir vielleicht jemand weiterhelfen?

Vielen Dank!!!

Grüsse und noch einen schönen Tag

programmieren, Java, Hashmap

Meistgelesene Fragen zum Thema Hashmap