Browse Source

完成w8作业

main
jingjiaying 2 months ago
parent
commit
3c53d9fb7a
  1. 4
      pair/src/Pair.java
  2. 30
      w8/.gitignore
  3. 10
      w8/.idea/.gitignore
  4. 6
      w8/.idea/misc.xml
  5. 8
      w8/.idea/modules.xml
  6. 6
      w8/.idea/vcs.xml
  7. 31
      w8/src/com/example/Pair.java
  8. 15
      w8/src/com/example/PairTest.java
  9. 11
      w8/w8.iml
  10. BIN
      w8/屏幕截图 2026-04-28 215840.png

4
pair/src/Pair.java

@ -0,0 +1,4 @@
package PACKAGE_NAME;
public class Pair {
}

30
w8/.gitignore

@ -0,0 +1,30 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
.kotlin
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

10
w8/.idea/.gitignore

@ -0,0 +1,10 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 已忽略包含查询文件的默认文件夹
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/

6
w8/.idea/misc.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
w8/.idea/modules.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/w8.iml" filepath="$PROJECT_DIR$/w8.iml" />
</modules>
</component>
</project>

6
w8/.idea/vcs.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

31
w8/src/com/example/Pair.java

@ -0,0 +1,31 @@
package com.example;
public class Pair<K,V> {
private K key;
private V value;
public Pair(K key,V value){
this.key = key;
this.value = value;
}
public K getKey(){
return key;
}
public void setKey(K key){
this.key = key;
}
public V getValue(){
return value;
}
public void setValue(V value){
this.value =value;
}
@Override
public String toString(){
return "Pair{"+"key="+key+",value="+value+"}";
}
public static <K,V>Pair<V,K>swap(Pair<K,V>pair){
return new Pair<>(pair.getValue(), pair.getKey());
}
}

15
w8/src/com/example/PairTest.java

@ -0,0 +1,15 @@
package com.example;
public class PairTest {
public static void main(String[] args){
Pair<String,Integer>pair1 = new Pair<>("年龄",20);
System.out.println("交换前:" + pair1);
Pair<Integer,String>swapped1 = Pair.swap(pair1);
System.out.println("交换后:"+swapped1);
System.out.println("---------------------");
Pair<Integer,String>pair2 = new Pair<>(1001,"张三");
System.out.println("交换前:" + pair2);
Pair<String,Integer>swapped2 = Pair.swap(pair2);
System.out.println("交换后:" +swapped2);
}
}

11
w8/w8.iml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

BIN
w8/屏幕截图 2026-04-28 215840.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

Loading…
Cancel
Save