Skip to content

Commit a1f59c3

Browse files
Closing scanners.
1 parent 4f45c5a commit a1f59c3

27 files changed

+29
-4
lines changed

Conversions/AnyBaseToAnyBase.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static void main(String[] args) {
5252
}
5353
}
5454
System.out.println(base2base(n, b1, b2));
55+
in.close();
5556
}
5657

5758
/**

Conversions/AnytoAny.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static void main(String[] args) {
2424
dec /= db;
2525
}
2626
System.out.println(dn);
27+
scn.close();
2728
}
2829

2930
}

Conversions/DecimalToBinary.java

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static void bitwiseConversion() {
5353
n >>= 1;
5454
}
5555
System.out.println("\tBinary number: " + b);
56+
input.close();
5657
}
5758

5859
}

Conversions/HexToOct.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public static void main(String args[]) {
6464
// convert decimal to octal
6565
octalnum = decimal2octal(decnum);
6666
System.out.println("Number in octal: " + octalnum);
67-
68-
67+
scan.close();
6968
}
7069
}

Conversions/HexaDecimalToDecimal.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void main(String args[]) {
3434
and it returns the decimal form in the variable dec_output.
3535
*/
3636
System.out.println("Number in Decimal: " + dec_output);
37-
37+
scan.close();
3838

3939
}
4040
}

Conversions/OctalToHexadecimal.java

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static void main(String args[]) {
5959
// Pass the decimla number to function and get converted Hex form of the number
6060
String hex = DecimalToHex(decimal);
6161
System.out.println("The Hexadecimal equivalant is: " + hex);
62+
input.close();
6263
}
6364
}
6465

DataStructures/Graphs/BellmanFord.java

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public void go()//Interactive run for understanding the class first time. Assume
100100
System.out.println();
101101
}
102102
}
103+
sc.close();
103104
}
104105
/**
105106
* @param source Starting vertex

DataStructures/HashMap/Hashing/Main.java

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static void main(String[] args) {
4242
return;
4343
}
4444
}
45+
In.close();
4546
}
4647
}
4748
}

DataStructures/Trees/RedBlackBST.java

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ public void insertDemo() {
309309
printTreepre(root);
310310
break;
311311
}
312+
scan.close();
312313
}
313314

314315
public void deleteDemo() {

DynamicProgramming/EditDistance.java

+1
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ public static void main(String[] args) {
7474
//ans stores the final Edit Distance between the two strings
7575
int ans = minDistance(s1, s2);
7676
System.out.println("The minimum Edit Distance between \"" + s1 + "\" and \"" + s2 + "\" is " + ans);
77+
input.close();
7778
}
7879
}

DynamicProgramming/Fibonacci.java

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static void main(String[] args) {
2222
System.out.println(fibMemo(n));
2323
System.out.println(fibBotUp(n));
2424
System.out.println(fibOptimized(n));
25+
sc.close();
2526
}
2627

2728
/**

DynamicProgramming/LongestIncreasingSubsequence.java

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static void main(String[] args) {
1717
}
1818

1919
System.out.println(LIS(ar));
20+
sc.close();
2021
}
2122

2223
private static int upperBound(int[] ar, int l, int r, int key) {

Maths/PrimeCheck.java

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static void main(String[] args) {
1313
} else {
1414
System.out.println(n + " is not a prime number");
1515
}
16+
scanner.close();
1617
}
1718

1819
/***

MinimizingLateness/MinimizingLateness.java

+1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ public static void main(String[] args) throws IOException {
5353
System.out.println();
5454
System.out.println("Output Data : ");
5555
System.out.println(lateness);
56+
in.close();
5657
}
5758
}

Misc/PalindromePrime.java

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static void main(String[] args) { // Main funtion
99
System.out.println("Enter the quantity of First Palindromic Primes you want");
1010
int n = in.nextInt(); // Input of how many first pallindromic prime we want
1111
functioning(n); // calling function - functioning
12+
in.close();
1213
}
1314

1415
public static boolean prime(int num) { // checking if number is prime or not

Others/Dijkshtra.java

+1
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,6 @@ else if (i != src) {
8080
System.out.print("-1" + " ");
8181
}
8282
}
83+
in.close();
8384
}
8485
}

Others/InsertDeleteInArray.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ public static void main(String[] args) {
4444
}
4545
for (i = 0; i < size2 - 1; i++)
4646
System.out.println(b[i]);
47+
s.close();
4748
}
4849
}

Others/LowestBasePalindrome.java

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static void main(String[] args) {
2929
}
3030
System.out.println(n + " is a palindrome in base " + lowestBasePalindrome(n));
3131
System.out.println(base2base(Integer.toString(n), 10, lowestBasePalindrome(n)));
32+
in.close();
3233
}
3334

3435
/**

Others/PerlinNoise.java

+1
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,6 @@ public static void main(String[] args) {
162162

163163
System.out.println();
164164
}
165+
in.close();
165166
}
166167
}

Others/PowerOfTwoOrNot.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static void main(String[] args) {
2020
} else {
2121
System.out.println("Number is not a power of two");
2222
}
23+
sc.close();
2324
}
2425

2526

@@ -32,5 +33,4 @@ public static void main(String[] args) {
3233
public static boolean checkIfPowerOfTwoOrNot(int number) {
3334
return number != 0 && ((number & (number - 1)) == 0);
3435
}
35-
3636
}

Others/ReturnSubsequence.java

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static void main(String[] args) {
1313
for (int i = 0; i < subsequence.length; i++) {
1414
System.out.println(subsequence[i]);
1515
}
16+
s.close();
1617
}
1718

1819
/**

Others/RootPrecision.java

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public static void main(String[] args) {
1414
// P is precision value for eg - P is 3 in 2.564 and 5 in 3.80870.
1515
int P = scn.nextInt();
1616
System.out.println(squareRoot(N, P));
17+
18+
scn.close();
1719
}
1820

1921
public static double squareRoot(int N, int P) {

Others/SJF.java

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Schedule {
6767
processes.add(p);
6868
burstAll += p.burstTime;
6969
}
70+
in.close();
7071

7172
}
7273

Others/StackPostfixNotation.java

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static void main(String[] args) {
77
Scanner scanner = new Scanner(System.in);
88
String post = scanner.nextLine(); // Takes input with spaces in between eg. "1 21 +"
99
System.out.println(postfixEvaluate(post));
10+
scanner.close();
1011
}
1112

1213
// Evaluates the given postfix expression string and returns the result.
@@ -35,6 +36,7 @@ public static int postfixEvaluate(String exp) {
3536
// "+", "-", "*", "/"
3637
}
3738
}
39+
tokens.close();
3840
return s.pop();
3941
}
4042
}

Others/TopKWords.java

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static void main(String[] args) {
8282
for (int i = 0; i < k; i++) {
8383
System.out.println(list.get(list.size() - i - 1));
8484
}
85+
input.close();
8586
}
8687
}
8788

Others/TowerOfHanoi.java

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ public static void main(String[] args) {
2222
Scanner scanner = new Scanner(System.in);
2323
int numberOfDiscs = scanner.nextInt(); //input of number of discs on pole 1
2424
shift(numberOfDiscs, "Pole1", "Pole2", "Pole3"); //Shift function called
25+
scanner.close();
2526
}
2627
}

ciphers/Caesar.java

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public static void main(String[] args) {
126126
case 'd':
127127
System.out.println("DECODED MESSAGE IS \n" + decode(message, shift));
128128
}
129+
input.close();
129130
}
130131

131132
}

0 commit comments

Comments
 (0)