Browse Source

完成w7作业

main
jingjiaying 2 months ago
parent
commit
e5dfd59362
  1. 30
      w7/.gitignore
  2. 10
      w7/.idea/.gitignore
  3. 6
      w7/.idea/misc.xml
  4. 8
      w7/.idea/modules.xml
  5. 6
      w7/.idea/vcs.xml
  6. 5
      w7/scores.txt
  7. 37
      w7/src/Main.java
  8. 11
      w7/w7.iml
  9. BIN
      w7/屏幕截图 2026-04-27 105547.png
  10. BIN
      w7/屏幕截图 2026-04-27 110305.png
  11. BIN
      w7/屏幕截图 2026-04-27 110818.png
  12. BIN
      w7/屏幕截图 2026-04-27 111134.png

30
w7/.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
w7/.idea/.gitignore

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

6
w7/.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
w7/.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$/w7.iml" filepath="$PROJECT_DIR$/w7.iml" />
</modules>
</component>
</project>

6
w7/.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>

5
w7/scores.txt

@ -0,0 +1,5 @@
90
99
100
98
96

37
w7/src/Main.java

@ -0,0 +1,37 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
int sum = 0;
int count = 0;
try (BufferedReader br = new BufferedReader(new FileReader("scores.txt"))){
String line;
while ((line = br.readLine())!= null){
line = line.trim();
if(line.isEmpty()){
continue;
}
int score = Integer.parseInt(line);
sum +=score;
count++;
}
if (count > 0){
double avg = (double)sum / count;
System.out.println("平均分:"+avg);
} else {
System.out.println("文件中无有效成绩");
}
} catch (NumberFormatException e){
System.out.println("文字内容不是数字,无法转换为成绩");
} catch (java.io.FileNotFoundException e){
System.out.println("错误,找不到scores.txt文件");
} catch (IOException e){
System.out.println("文件操作异常:"+e.getMessage());
}
}
}

11
w7/w7.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
w7/屏幕截图 2026-04-27 105547.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

BIN
w7/屏幕截图 2026-04-27 110305.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

BIN
w7/屏幕截图 2026-04-27 110818.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

BIN
w7/屏幕截图 2026-04-27 111134.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

Loading…
Cancel
Save