<span style="color:#323232;">// A generic class to store a pair of values of any type that implements Comparable
</span><span style="color:#323232;">public class Pair<T extends Comparable<T>> {
</span><span style="color:#323232;"> // Declare two private fields of type T
</span><span style="color:#323232;"> private T first;
</span><span style="color:#323232;"> private T second;
</span><span style="color:#323232;">
</span><span style="color:#323232;"> // Define a constructor that takes two arguments of type T
</span><span style="color:#323232;"> public Pair(T first, T second) {
</span><span style="color:#323232;"> // Assign the arguments to the fields
</span><span style="color:#323232;"> this.first = first;
</span><span style="color:#323232;"> this.second = second;
</span><span style="color:#323232;"> }
</span><span style="color:#323232;">
</span><span style="color:#323232;"> // Define a getter method for the first field
</span><span style="color:#323232;"> public T getFirst() {
</span><span style="color:#323232;"> return first;
</span><span style="color:#323232;"> }
</span><span style="color:#323232;">
</span><span style="color:#323232;"> // Define a getter method for the second field
</span><span style="color:#323232;"> public T getSecond() {
</span><span style="color:#323232;"> return second;
</span><span style="color:#323232;"> }
</span><span style="color:#323232;">
</span><span style="color:#323232;"> // Define a method to compare the two values and return the larger one
</span><span style="color:#323232;"> public T max() {
</span><span style="color:#323232;"> // Use the compareTo method of the Comparable interface
</span><span style="color:#323232;"> if (first.compareTo(second) > 0) {
</span><span style="color:#323232;"> return first;
</span><span style="color:#323232;"> } else {
</span><span style="color:#323232;"> return second;
</span><span style="color:#323232;"> }
</span><span style="color:#323232;"> }
</span><span style="color:#323232;">
</span><span style="color:#323232;"> // Define a method to compare the two values and return the smaller one
</span><span style="color:#323232;"> public T min() {
</span><span style="color:#323232;"> // Use the compareTo method of the Comparable interface
</span><span style="color:#323232;"> if (first.compareTo(second) < 0) {
</span><span style="color:#323232;"> return first;
</span><span style="color:#323232;"> } else {
</span><span style="color:#323232;"> return second;
</span><span style="color:#323232;"> }
</span><span style="color:#323232;"> }
</span><span style="color:#323232;">
</span><span style="color:#323232;"> // Define a method to return a string representation of the pair
</span><span style="color:#323232;"> public String toString() {
</span><span style="color:#323232;"> return "(" + first + ", " + second + ")";
</span><span style="color:#323232;"> }
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;">public class Main {
</span><span style="color:#323232;"> // Test the Pair class with different types
</span><span style="color:#323232;"> public static void main(String[] args) {
</span><span style="color:#323232;"> // Create a pair of integers
</span><span style="color:#323232;"> Pair<Integer> p1 = new Pair<>(10, 20);
</span><span style="color:#323232;"> System.out.println("p1 = " + p1);
</span><span style="color:#323232;"> System.out.println("The larger value of p1 is " + p1.max());
</span><span style="color:#323232;"> System.out.println("The smaller value of p1 is " + p1.min());
</span><span style="color:#323232;">
</span><span style="color:#323232;"> // Create a pair of strings
</span><span style="color:#323232;"> Pair<String> p2 = new Pair<>("Hello", "World");
</span><span style="color:#323232;"> System.out.println("p2 = " + p2);
</span><span style="color:#323232;"> System.out.println("The larger value of p2 is " + p2.max());
</span><span style="color:#323232;"> System.out.println("The smaller value of p2 is " + p2.min());
</span><span style="color:#323232;"> }
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span>
Does this federate to kbin.social?
Testing if it works better now than last week
More kbin codeblocks (so I can use kbin.earth for testing too)
var k = 3;...
Test (kbin.run)
Some thread from Mbin
Mbin Codeblock Federation test
How does this look on kbin.social?...
Codeblock Federation Test
How does this look on kbin.social?...
Testing spoiler federation
How does this federate to kbin?...
deleted_by_author