diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-23 19:56:21 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-23 19:56:21 +0100 |
| commit | f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030 (patch) | |
| tree | e97b3042d70c219ae232b875b629faab892b4244 /challenge-218/ziameraj16/java/MaximumProduct.java | |
| parent | a0378812481339d92fae9464fbd9e98bcca04ff5 (diff) | |
| download | perlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.tar.gz perlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.tar.bz2 perlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.zip | |
- Added solutions by Mark Anderson.
- Added solutions by Stephen G. Lynn.
- Added solutions by David Ferrone.
- Added solutions by Thomas Kohler.
- Added solutions by Niels van Dijke.
- Added solutions by W. Luis Mochan.
- Added solutions by Steven Wilson.
- Added solutions by Robert DiCicco.
- Added solutions by Lubos Kolouch.
Diffstat (limited to 'challenge-218/ziameraj16/java/MaximumProduct.java')
| -rw-r--r-- | challenge-218/ziameraj16/java/MaximumProduct.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-218/ziameraj16/java/MaximumProduct.java b/challenge-218/ziameraj16/java/MaximumProduct.java new file mode 100644 index 0000000000..66c8277c82 --- /dev/null +++ b/challenge-218/ziameraj16/java/MaximumProduct.java @@ -0,0 +1,26 @@ +import java.util.*; + +public class MaximumProduct { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + List<Integer> values = Arrays.stream(scanner.nextLine().split(",")).map(Integer::valueOf).toList(); + int maxProduct = 0; + String str = null; + int size = values.size(); + for (int x = 0; x < size - 2; x++) { + for (int y = x + 1; y < size - 1; y++) { + for (int z = y + 1; z < size; z++) { + Integer first = values.get(x); + Integer second = values.get(y); + Integer third = values.get(z); + if (first * second * third > maxProduct) { + maxProduct = first * second * third; + str = String.format("%s x %s x %s => %s", first, second, third, maxProduct); + } + } + } + } + System.out.println(str); + } +} |
