gpt4 book ai didi

java - 获得不同的输出

转载 作者:行者123 更新时间:2023-12-01 13:29:05 25 4
gpt4 key购买 nike

我得到了不同的输出。我想要的输出是-测验:66%实验室:88%实验室出席率:81%期中考试:91%最终:不适用总体平均分:85%。但我越来越

输出:

[I@176c74b
[I@116471f
[I@1975b59
[I@lee3914

我的方法归一化应该得到百分比,然后转到平均方法。我将此方法称为 quizArray、labArray、attendance、midterms,以尝试获取每个项目的成绩。

import java.io.*;
import java.util.*;

public class FindGrade {
public static final int NUM_SCORE_TYPES = 5;

public static void main(String[] args) {
Scanner scan = null;
int[] quizArray = null;
int[] labArray = null;
int[] attendance = null;
int[] midterms = null;
int quizgrade = 0;
int labgrade = 0;
int attendance_1 = 0;
int midterms_1 = 0;
String name;


try {
scan = new Scanner(new File("input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}

// each iteration is for single exam type (ie: Quizzes is the 1st one)
for (int i = 0; i < NUM_SCORE_TYPES; i++) {

name = scan.next();
int numScores = scan.nextInt();
int maxGrade = scan.nextInt();

if (name.equals("Quizzes")) {
quizArray = new int[numScores];
readScores(quizArray, numScores, scan);


} else if (name.equals("Labs")) {
labArray = new int[numScores];
readScores(labArray, numScores, scan);

} else if (name.equals("Lab_attendance")) {
attendance = new int[numScores];
readScores(attendance, numScores, scan);

} else if (name.equals("Midterms")) {
midterms = new int[numScores];
readScores(midterms, numScores, scan);

}

}

}


public static void readScores(int[] scoreArray, int numScores, Scanner scan) {
for (int i = 0; i < numScores; i++) {
scoreArray[i] = scan.nextInt();
}
average(scoreArray, numScores);
}

public static int normalize(int[] scoreArray, int maxGrade) {
int total = 0;
for (int i = 0; i < scoreArray.length; i++) {
total += scoreArray[i];
}
int percent = Math.round(total * 100 / maxGrade);
return percent;
}

public static double average(double[] scoreArray, int numScores) {
double sum = 0;
for (int i = 0; i < scoreArray.length; i++) {
sum += scoreArray[i];
}
double average = sum / numScores;

return average;


}

输入文件:

Quizzes 8 10
5 8 9 10 4 0 10 7
Labs 6 100
95 90 100 87 63 92
Lab_attendance 16 1
1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1
Midterms 2 100
87 94
Final 0 100

最佳答案

每个对象都有toString()方法,其默认将显示类名表示,然后添加@,然后添加哈希码。我假设您正在打印 System.out.println(someArray)

您应该使用Arrays#toString() (下面是它的实现,以便您更好地理解它):

3860     public static String toString(int[] a) { {
3861 if (a == null)
3862 return "null";
3863 int iMax = a.length - 1;
3864 if (iMax == -1)
3865 return "[]";
3866
3867 StringBuilder b = new StringBuilder();
3868 b.append('[');
3869 for (int i = 0; ; i++) {
3870 b.append(a[i]);
3871 if (i == iMax)
3872 return b.append(']').toString();
3873 b.append(", ");
3874 }
3875 }

关于java - 获得不同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21661111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com