Java:
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
public class StudentList {
public static void main(String[] args) {
Map<String, String> students = new HashMap<>();
Scanner sc = new Scanner(System.in);
String num;
String name;
System.out.print("Enter student number 1: ");
num = sc.nextLine();
System.out.print("Enter first name 1: ");
name = sc.nextLine();
students.put(num, name);
System.out.print("Enter student number 2: ");
num = sc.nextLine();
System.out.print("Enter first name 2: ");
name = sc.nextLine();
students.put(num, name);
System.out.print("Enter student number 3: ");
num = sc.nextLine();
System.out.print("Enter first name 3: ");
name = sc.nextLine();
students.put(num, name);
System.out.println("Student List:");
for (Map.Entry x : students.entrySet()) {
System.out.println(x.getKey() + " " + x.getValue());
}
students.remove(num, name);
System.out.print("Enter your student number: ");
String num3 = sc.nextLine();
System.out.print("Enter your first name: ");
String name3 = sc.nextLine();
students.put(num3, name3);
System.out.println("Student List:");
for (Map.Entry x : students.entrySet()) {
System.out.println(x.getKey() + " " + x.getValue());
}
}
}
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.