mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-19 17:54:42 +08:00
Closing scanners.
This commit is contained in:
@ -80,5 +80,6 @@ public class Dijkshtra {
|
||||
System.out.print("-1" + " ");
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
@ -44,5 +44,6 @@ public class InsertDeleteInArray {
|
||||
}
|
||||
for (i = 0; i < size2 - 1; i++)
|
||||
System.out.println(b[i]);
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ public class LowestBasePalindrome {
|
||||
}
|
||||
System.out.println(n + " is a palindrome in base " + lowestBasePalindrome(n));
|
||||
System.out.println(base2base(Integer.toString(n), 10, lowestBasePalindrome(n)));
|
||||
in.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,5 +162,6 @@ public class PerlinNoise {
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ public class PowerOfTwoOrNot {
|
||||
} else {
|
||||
System.out.println("Number is not a power of two");
|
||||
}
|
||||
sc.close();
|
||||
}
|
||||
|
||||
|
||||
@ -32,5 +33,4 @@ public class PowerOfTwoOrNot {
|
||||
public static boolean checkIfPowerOfTwoOrNot(int number) {
|
||||
return number != 0 && ((number & (number - 1)) == 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ public class ReturnSubsequence {
|
||||
for (int i = 0; i < subsequence.length; i++) {
|
||||
System.out.println(subsequence[i]);
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,8 @@ public class RootPrecision {
|
||||
// P is precision value for eg - P is 3 in 2.564 and 5 in 3.80870.
|
||||
int P = scn.nextInt();
|
||||
System.out.println(squareRoot(N, P));
|
||||
|
||||
scn.close();
|
||||
}
|
||||
|
||||
public static double squareRoot(int N, int P) {
|
||||
|
@ -67,6 +67,7 @@ class Schedule {
|
||||
processes.add(p);
|
||||
burstAll += p.burstTime;
|
||||
}
|
||||
in.close();
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ public class StackPostfixNotation {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String post = scanner.nextLine(); // Takes input with spaces in between eg. "1 21 +"
|
||||
System.out.println(postfixEvaluate(post));
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
// Evaluates the given postfix expression string and returns the result.
|
||||
@ -35,6 +36,7 @@ public class StackPostfixNotation {
|
||||
// "+", "-", "*", "/"
|
||||
}
|
||||
}
|
||||
tokens.close();
|
||||
return s.pop();
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ public class TopKWords {
|
||||
for (int i = 0; i < k; i++) {
|
||||
System.out.println(list.get(list.size() - i - 1));
|
||||
}
|
||||
input.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,5 +22,6 @@ class TowerOfHanoi {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int numberOfDiscs = scanner.nextInt(); //input of number of discs on pole 1
|
||||
shift(numberOfDiscs, "Pole1", "Pole2", "Pole3"); //Shift function called
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user