代码拉取完成,页面将自动刷新
//***********************************************************************************************
//SodaSurvey.java Author:WZW
//
//Demonstrates the use of a two-dimensional array.
//***********************************************************************************************
import java.text.DecimalFormat;
public class eg8_14 {
//-------------------------------------------------------------------------------------------
//Determines and prints the average of each row (soda) and each
//column (respondent) of the survey scores.
//-------------------------------------------------------------------------------------------
public static void main(String[] args) {
int[][] scores = {
{3, 4, 5, 2, 1, 4, 3, 2, 4, 4},
{2, 4, 3, 4, 3, 3, 2, 1, 2, 2},
{3, 5, 4, 5, 5, 3, 2, 5, 5, 5},
{1, 1, 1, 3, 1, 2, 1, 3, 2, 4}
};
final int SODAS = scores.length;
final int PEOPLE = scores[0].length;
int[] sodaSum = new int[SODAS];
int[] personSum = new int[PEOPLE];
for (int soda = 0; soda < SODAS; soda++)
for (int person = 0; person < PEOPLE; person++)
{
sodaSum[soda]+=scores[soda][person];
personSum[person]+=scores[soda][person];
}
DecimalFormat fmt =new DecimalFormat("0.#");
System.out.println("Averages:\n");
for (int soda=0;soda<SODAS;soda++)
System.out.println("Soda #" +(soda+1)+":" +fmt.format((float)sodaSum[soda]/PEOPLE));
System.out.println();
for (int person=0;person<PEOPLE;person++)
System.out.println("Person #"+(person+1)+":"+fmt.format((float)personSum[person]/SODAS));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。