From fb4177a76399ea929609ff4923301d10712c1caf Mon Sep 17 00:00:00 2001 From: femsci Date: Thu, 28 Mar 2024 20:23:03 +0100 Subject: [PATCH] task 2 --- Mrrrp.java | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Mrrrp.java diff --git a/Mrrrp.java b/Mrrrp.java new file mode 100644 index 0000000..07396b1 --- /dev/null +++ b/Mrrrp.java @@ -0,0 +1,65 @@ +import java.util.Arrays; + +/* + * TASK 2 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/2 + * by femsci + */ + +public class Mrrrp { + public static void main(String[] args) { + if (args.length != 3) { + System.err.printf("Invalid argument count: %d. Expected 3.\n", args.length); + System.exit(2); + } + + sortContrained_ꭥmꭥ(args); + fancyCollectionsAndStreamsΘѡΘ(args); + } + + public static void sortContrained_ꭥmꭥ(String[] args) { + int a, b, c; + try { + a = Integer.parseInt(args[0]); + b = Integer.parseInt(args[1]); + c = Integer.parseInt(args[2]); + } catch (Exception e) { + System.err.println("Invalid arguments."); + System.exit(1); + return; + } + + int buf; + + // eepy sort (fixed 3:) + + if (a > b) { + buf = a; + a = b; + b = buf; + } + if (a > c) { + buf = a; + a = c; + c = buf; + } + if (b > c) { + buf = b; + b = c; + c = buf; + } + + System.out.printf("%d %d %d\n", a, b, c); + } + + // cute one-liner + public static void fancyCollectionsAndStreamsΘѡΘ(String[] args) { + try { + Arrays.asList(args).stream().map(Integer::parseInt).sorted().forEach(n -> System.out.printf("%d ", n)); + System.err.println(); + } catch (Exception e) { + System.err.println("Invalid arguments."); + System.exit(1); + } + } +} diff --git a/README.md b/README.md index a4b6575..746d12a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PPJ -This branch contains the solution for the **nth task**. +This branch contains the solution for the **2nd task**. [Go back to main](/femsci/ppj/src/branch/nya)