Skip to content

Commit dd73b46

Browse files
committed
Update Main.java
fixing bug Program is causing a NoSuchElementException
1 parent ecfbadc commit dd73b46

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

DataStructures/HashMap/Hashing/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ public static void main(String[] args) {
88
int choice, key;
99

1010
HashMap h = new HashMap(7);
11+
Scanner In = new Scanner(System.in);
1112

1213
while (true) {
1314
System.out.println("Enter your Choice :");
1415
System.out.println("1. Add Key");
1516
System.out.println("2. Delete Key");
1617
System.out.println("3. Print Table");
1718
System.out.println("4. Exit");
18-
19-
Scanner In = new Scanner(System.in);
20-
19+
2120
choice = In.nextInt();
2221

2322
switch (choice) {
@@ -39,10 +38,11 @@ public static void main(String[] args) {
3938
break;
4039
}
4140
case 4: {
41+
In.close();
4242
return;
4343
}
4444
}
45-
In.close();
45+
4646
}
4747
}
4848
}

0 commit comments

Comments
 (0)