Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class dictionery {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String command="";
- Dictionary geek = new Hashtable();
- while (!command.equals("end")) {
- command = scan.nextLine().toLowerCase();
- if (command.equals("add")) {
- System.out.println("Enter student number:");
- String number = scan.nextLine().toLowerCase();
- System.out.println("Enter student name:");
- String name = scan.nextLine().toLowerCase();
- geek.put(number,name );
- }else if(command.equals("rem")){
- System.out.println("Enter student number to remove:");
- String remove = scan.nextLine().toLowerCase();
- geek.remove(remove);
- }else if(command.equals("cnt")){
- System.out.println("\nSize of Dictionary : " + geek.size());
- }else if(command.equals("prn")){
- for (Enumeration i = geek.elements(); i.hasMoreElements();)
- {
- System.out.println("Value in Dictionary : " + i.nextElement());
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment