aboutsummaryrefslogtreecommitdiff
path: root/challenge-243/deadmarshal/java/Ch1.java
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-11-15 21:27:27 +0000
committerGitHub <noreply@github.com>2023-11-15 21:27:27 +0000
commit9715f6a957689e688b2c4bcbd491e77d318fcbe7 (patch)
tree56fc4453c1ddfc507391dcdc3764e56072f2f08b /challenge-243/deadmarshal/java/Ch1.java
parentb3a11494dfbcb9be7052f8f6f32a9afec052485f (diff)
parent7d92a145e089e59f0f830843ba91cd7223bc6c98 (diff)
downloadperlweeklychallenge-club-9715f6a957689e688b2c4bcbd491e77d318fcbe7.tar.gz
perlweeklychallenge-club-9715f6a957689e688b2c4bcbd491e77d318fcbe7.tar.bz2
perlweeklychallenge-club-9715f6a957689e688b2c4bcbd491e77d318fcbe7.zip
Merge pull request #9075 from deadmarshal/TWC243_extra
TWC243 extra solutions
Diffstat (limited to 'challenge-243/deadmarshal/java/Ch1.java')
-rw-r--r--challenge-243/deadmarshal/java/Ch1.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-243/deadmarshal/java/Ch1.java b/challenge-243/deadmarshal/java/Ch1.java
new file mode 100644
index 0000000000..ae2eb24e29
--- /dev/null
+++ b/challenge-243/deadmarshal/java/Ch1.java
@@ -0,0 +1,20 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class Ch1 {
+ public static void main(String[] args) {
+ ArrayList<Integer> list1 = new ArrayList<>(List.of(1,3,2,3,1));
+ ArrayList<Integer> list2 = new ArrayList<>(List.of(2,4,3,5,1));
+ System.out.println(reverse_pairs(list1));
+ System.out.println(reverse_pairs(list2));
+ }
+
+ private static int reverse_pairs(List<Integer> list) {
+ int count = 0;
+ for(int i = 0; i < list.size()-1; ++i)
+ for(int j = i+1; j < list.size(); ++j)
+ if(list.get(i) > 2 * list.get(j)) count++;
+ return count;
+ }
+}
+