Fixing resource leaks

master
sgoudham 4 years ago
parent 0ed367c6eb
commit 1277fecc35
No known key found for this signature in database
GPG Key ID: EF51A29A50FB754C

@ -14,6 +14,7 @@ public class SimpleArrays {
values[currentSize] = in.nextInt(); values[currentSize] = in.nextInt();
currentSize++; currentSize++;
} }
in.close();
//Find The Largest Value //Find The Largest Value
double largest = values[0]; double largest = values[0];

@ -25,6 +25,7 @@ public class UsingScanner {
double pricePerOunce = packPrice / packVolume; double pricePerOunce = packPrice / packVolume;
System.out.printf("Price per ounce: %8.2f", pricePerOunce); System.out.printf("Price per ounce: %8.2f", pricePerOunce);
in.close();
} }
} }

@ -57,12 +57,11 @@ public class WorkingWithStrings {
System.out.println("The Last Letter Of The Name is " + last); System.out.println("The Last Letter Of The Name is " + last);
// Generating userID from strings entered // Generating userID from strings entered
Scanner sc = new Scanner(System.in);
System.out.println("Please enter your first name: "); System.out.println("Please enter your first name: ");
String firstName = sc.next(); String firstName = in.next();
System.out.println("Please enter your last name: "); System.out.println("Please enter your last name: ");
String secondName = sc.next(); String secondName = in.next();
sc.close(); in.close();
LocalDateTime nowIsTheTime = LocalDateTime.now(); LocalDateTime nowIsTheTime = LocalDateTime.now();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd"); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd");

Loading…
Cancel
Save