From c8780aa992614b35d9203ca54b66c5397ae16a62 Mon Sep 17 00:00:00 2001 From: LeiJuntao <2606542098@qq.com> Date: Tue, 28 Apr 2026 11:34:04 +0800 Subject: [PATCH] W8 --- W8/Pair.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 W8/Pair.java diff --git a/W8/Pair.java b/W8/Pair.java new file mode 100644 index 0000000..976abea --- /dev/null +++ b/W8/Pair.java @@ -0,0 +1,26 @@ +public class Pair { + private K key; + private V value; + + // 构造方法 + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + // Getter 和 Setter + public K getKey() { return key; } + public V getValue() { return value; } + public void setKey(K key) { this.key = key; } + public void setValue(V value) { this.value = value; } + + @Override + public String toString() { + return "(" + key + ", " + value + ")"; + } + + // 静态交换方法 + public static Pair swap(Pair p) { + return new Pair<>(p.getValue(), p.getKey()); + } +}