diff --git a/main/w8/Pair.java b/main/w8/Pair.java new file mode 100644 index 0000000..f97b1e6 --- /dev/null +++ b/main/w8/Pair.java @@ -0,0 +1,23 @@ +public class Pair{ + private K key; + private V value; + public Pair(K key,V value){ + this.key=key; + this.value=value; + } + 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; + } + public static Pair swap(Pair pair){ + return new Pair<>(pair.getValue(), pair.getKey()); + } +} \ No newline at end of file diff --git a/main/w8/Test.java b/main/w8/Test.java new file mode 100644 index 0000000..843709e --- /dev/null +++ b/main/w8/Test.java @@ -0,0 +1,10 @@ +public class Test { + public static void main(String[] args) { + Pair pair=new Pair<>(1,"a"); + System.out.println(pair.getKey()); + System.out.println(pair.getValue()); + Pair swappedPair=Pair.swap(pair); + System.out.println(swappedPair.getKey()); + System.out.println(swappedPair.getValue()); + } +} \ No newline at end of file diff --git a/main/w8/代码运行截图.docx b/main/w8/代码运行截图.docx new file mode 100644 index 0000000..02943b4 Binary files /dev/null and b/main/w8/代码运行截图.docx differ