summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaidong Ji2018-08-07 10:28:43 -0500
committerHaidong Ji2018-08-07 10:28:43 -0500
commitb1a00e657e9534ae243d4fa1373d54aaff2847dc (patch)
treece795ae1d1f4440b52d2847c6f5143890fdf340a
parenteb3a6e192072e9ddb82c5a9cf283196558d61e45 (diff)
Used FastScanner. Had to change "static class" to "final class"
-rw-r--r--AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java35
1 files changed, 31 insertions, 4 deletions
diff --git a/AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java b/AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java
index 18b9521..dbe4ee6 100644
--- a/AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java
+++ b/AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java
@@ -1,4 +1,5 @@
-import java.util.Scanner;
+import java.io.*;
+import java.util.*;
public class MaxPairProduct {
int numberOfIntegers;
@@ -14,7 +15,7 @@ public class MaxPairProduct {
}
public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
+ FastScanner s = new FastScanner(System.in);
int n = s.nextInt();
MaxPairProduct mpp = new MaxPairProduct(n);
@@ -22,8 +23,6 @@ public class MaxPairProduct {
mpp.newNumber(s.nextInt());
}
- s.close();
-
System.out.println(mpp.getProduct());
}
@@ -57,3 +56,31 @@ public class MaxPairProduct {
}
}
+
+final class FastScanner {
+ BufferedReader br;
+ StringTokenizer st;
+
+ FastScanner(InputStream stream) {
+ try {
+ br = new BufferedReader(new InputStreamReader(stream));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ String next() {
+ while (st == null || !st.hasMoreTokens()) {
+ try {
+ st = new StringTokenizer(br.readLine());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return st.nextToken();
+ }
+
+ int nextInt() {
+ return Integer.parseInt(next());
+ }
+} \ No newline at end of file