java。 急 ! 编程语言!

 我来答
fylsh
2015-12-21 · TA获得超过950个赞
知道小有建树答主
回答量:1472
采纳率:0%
帮助的人:1048万
展开全部
import java.util.Arrays;
import java.util.Random;
public class RandScoreTest {
private int[] scoresA;
private int[] scoresB;
private int[] scoresTotal;
private int scoreMax;
private transient Random random = new Random();
public static void main(String[] args) {
RandScoreTest randScoreTest = new RandScoreTest(150, 180, 50);
System.out.println("scores A:");
randScoreTest.printScoresA();
System.out.println("scores B:");
randScoreTest.printScoresB();
System.out.println("scores Total:");
randScoreTest.printScoresTotal();
randScoreTest.shuttleSortHighToLow();
System.out.println("scores Total low to high:");
randScoreTest.printScoresTotalInvert();
System.out.println("scores Total high to low:");
randScoreTest.printScoresTotal();
System.out.println("highest score:");
System.out.println(randScoreTest.getMaxScore());
System.out.println("lowest score:");
System.out.println(randScoreTest.getMinScore());
System.out.println("average score:");
System.out.println(randScoreTest.getAverageScore());
System.out.println("standard deviation:");
System.out.println(randScoreTest.standardDeviation());
}
public RandScoreTest(int aCount, int bCount, int scoreMax) {
scoresA = new int[aCount];
scoresB = new int[bCount];
scoresTotal = new int[aCount > bCount ? aCount : bCount];
this.scoreMax = scoreMax;
generateScores(scoresA);
generateScores(scoresB);
}
private void generateScores(int[] scores) {
for (int i = 0, len = scores.length; i < len; i++) {
scores[i] = random.nextInt(scoreMax);
scoresTotal[i] += scores[i];
}
}
public void printScoresA() {
printScores(scoresA);
}
public void printScoresB() {
printScores(scoresB);
}
public void printScoresTotal() {
printScores(scoresTotal);
}
private void printScores(int[] scores) {
System.out.println(Arrays.toString(scores));
}
public void printScoresTotalInvert() {
StringBuilder buf = new StringBuilder();
for (int i = scoresTotal.length - 1; i >= 0; i--) {
buf.append(scoresTotal[i]).append(",");
}
System.out.println(buf.toString());
}
public void shuttleSortHighToLow() {
for (int i = 0; i < scoresTotal.length - 1; i++) {
for (int j = i + 1; j < scoresTotal.length; j++) {
if (scoresTotal[i] <= scoresTotal[j]) {
int temp = scoresTotal[i];
scoresTotal[i] = scoresTotal[j];
scoresTotal[j] = temp;
}
}
}
}
public int getMaxScore() {
return scoresTotal[0];
}
public int getMinScore() {
return scoresTotal[scoresTotal.length - 1];
}
public int getAverageScore() {
int sum = 0;
for (int i = 0, len = scoresTotal.length; i < len; i++) {
sum += scoresTotal[i];
}
return sum / scoresTotal.length;
}
public double standardDeviation() {
long sum1 = 0;
int sum2 = 0;
int len = scoresTotal.length;
for (int i = 0; i < len; i++) {
sum1 += scoresTotal[i] * scoresTotal[i];
sum2 += scoresTotal[i];
}
return Math.pow((sum1 - sum2 * sum2 / len) / (len - 1), 0.5);
}
}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
独孤木人
2015-12-19 · TA获得超过2535个赞
知道小有建树答主
回答量:1757
采纳率:58%
帮助的人:682万
展开全部
代码太长,留邮箱吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
扈怀炜4h
2015-12-18 · TA获得超过6039个赞
知道大有可为答主
回答量:6907
采纳率:67%
帮助的人:1345万
展开全部
这么多,彩30分
追问
...可以加分
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式