diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-04-01 17:52:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-01 17:52:03 +0100 |
| commit | 544a134ff3b3251cfd3284fbf99cbfacaec5f80f (patch) | |
| tree | aeeb013f1da03244b36542a23f745a2f53de9e66 /challenge-263/ash/java | |
| parent | c866688956ed8d39e4bf4a136c85d1244105a567 (diff) | |
| parent | a4a5c909234335cbf64764b067d3d0f23829f8fc (diff) | |
| download | perlweeklychallenge-club-544a134ff3b3251cfd3284fbf99cbfacaec5f80f.tar.gz perlweeklychallenge-club-544a134ff3b3251cfd3284fbf99cbfacaec5f80f.tar.bz2 perlweeklychallenge-club-544a134ff3b3251cfd3284fbf99cbfacaec5f80f.zip | |
Merge pull request #9849 from ash/ash-263
Week 263 Task 1 by ash
Diffstat (limited to 'challenge-263/ash/java')
| -rw-r--r-- | challenge-263/ash/java/ch-1.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-263/ash/java/ch-1.java b/challenge-263/ash/java/ch-1.java new file mode 100644 index 0000000000..fe856b3e07 --- /dev/null +++ b/challenge-263/ash/java/ch-1.java @@ -0,0 +1,42 @@ +// Solution of Task 1 of The Weekly Challenge 263 +// https://theweeklychallenge.org/blog/perl-weekly-challenge-263/ + +/* +$ java ch-1.java +[1, 2] +[] +[4] +*/ + +import java.util.Arrays; +import java.util.ArrayList; + +public class Main { + public static void main(String[] args) { + int[][] tests = {{1, 5, 3, 2, 4, 2}, + {1, 2, 4, 3, 5}, + {5, 3, 2, 4, 2, 1}}; + int[] values = {2, 6, 4}; + + for (int c = 0; c != tests.length; c++) { + int[] data = tests[c]; + int value = values[c]; + + ArrayList<Integer> indices = solve(data, value); + System.out.println(indices); + } + } + + static ArrayList<Integer> solve(int[] data, int value) { + Arrays.sort(data); + + ArrayList<Integer> indices = new ArrayList<Integer>(); + for (int c = 0; c != data.length; c++) { + int current = data[c]; + if (current == value) indices.add(c); + if (current > value) break; + } + + return indices; + } +} |
