From 1277fecc353b3478b285c70e1cce307751dffb3a Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 8 Oct 2020 22:15:02 +0100 Subject: [PATCH] Fixing resource leaks --- 2018 - 2019/2018/Arrays/src/SimpleArrays.java | 1 + 2018 - 2019/2018/Using Scanner/src/UsingScanner.java | 1 + .../2018/Working With Strings/src/WorkingWithStrings.java | 7 +++---- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/2018 - 2019/2018/Arrays/src/SimpleArrays.java b/2018 - 2019/2018/Arrays/src/SimpleArrays.java index 82ff8e3..b83b014 100644 --- a/2018 - 2019/2018/Arrays/src/SimpleArrays.java +++ b/2018 - 2019/2018/Arrays/src/SimpleArrays.java @@ -14,6 +14,7 @@ public class SimpleArrays { values[currentSize] = in.nextInt(); currentSize++; } + in.close(); //Find The Largest Value double largest = values[0]; diff --git a/2018 - 2019/2018/Using Scanner/src/UsingScanner.java b/2018 - 2019/2018/Using Scanner/src/UsingScanner.java index 8acfbc7..ce76cd6 100644 --- a/2018 - 2019/2018/Using Scanner/src/UsingScanner.java +++ b/2018 - 2019/2018/Using Scanner/src/UsingScanner.java @@ -25,6 +25,7 @@ public class UsingScanner { double pricePerOunce = packPrice / packVolume; System.out.printf("Price per ounce: %8.2f", pricePerOunce); + in.close(); } } diff --git a/2018 - 2019/2018/Working With Strings/src/WorkingWithStrings.java b/2018 - 2019/2018/Working With Strings/src/WorkingWithStrings.java index 7311d88..f978f40 100644 --- a/2018 - 2019/2018/Working With Strings/src/WorkingWithStrings.java +++ b/2018 - 2019/2018/Working With Strings/src/WorkingWithStrings.java @@ -57,12 +57,11 @@ public class WorkingWithStrings { System.out.println("The Last Letter Of The Name is " + last); // Generating userID from strings entered - Scanner sc = new Scanner(System.in); System.out.println("Please enter your first name: "); - String firstName = sc.next(); + String firstName = in.next(); System.out.println("Please enter your last name: "); - String secondName = sc.next(); - sc.close(); + String secondName = in.next(); + in.close(); LocalDateTime nowIsTheTime = LocalDateTime.now(); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd");