当前位置:首页 » 考试成绩 » 二维数组学生成绩java

二维数组学生成绩java

发布时间: 2021-01-08 07:57:28

㈠ java编程 保存十个同学的三门功课成绩使用二维数组

import java.util.Scanner;

public class Demo {
public static void main(String[] args) {
int[][] a = new int[10][3];
String str[] = { "A", "B", "C" };
Scanner scan = new Scanner(System.in);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
System.out.print("输入第" + (1 + i) + "位同学的" + str[j] + "的分数:");
a[i][j] = scan.nextInt();
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
System.out.println("第" + (1 + i) + "位同学的" + str[j] + "的分数为:"+a[i][j]);

}
}
}

}

㈡ java二维数组怎么定义

java中使用 [][] 来定义二维数组,定义数组时也可同时初始化。

两种初始化形式:

格式1、动态初始化

数据类型 数组名 [ ][ ] = new 数据类型[m][n]
数据类型 [ ][ ] 数组名 = new 数据类型[m][n]
数据类型 [ ] 数组名 [ ] = new 数据类型[m][n]

举例:int [ ][ ] arr=new int [5][3]; 也可以理解为“5行3例”。

格式2、 静态初始化

数据类型 [ ][ ] 数组名 = {{元素1,元素2....},{元素1,元素2....},{元素1,元素2....}.....};

举例:int [ ][ ] arr={{22,15,32,20,18},{12,21,25,19,33},{14,58,34,24,66},}。

㈢ 一个年级有m个班,每个班有n个学生,编写java程序用二维数组保存学生成绩,计算学生平均成绩

publicclassScoreDemo{
publicstaticvoidmain(String[]args){
intm=2;//班级个数
intn=3;//每个班级的人数
int[][]ary=newint[m][n];
inputScore(ary);//输入每个人的分数,保存到数组
printAvg(ary);//打印平均分
}

privatestaticvoidprintAvg(int[][]ary){
intindex=0;//计算人数
inttotal=0;//累加总分
for(inti=0;i<ary.length;i++){
intclassTotal=0;//班级总分
for(intj=0;j<ary[i].length;j++){
index++;
intscore=ary[i][j];
classTotal+=score;
}
total+=classTotal;
System.out.println("---------"+(i+1)+"班考试情况---------");
System.out.println("班级总分"+classTotal+" 班级人数"+ary[i].length);
System.out.println((i+1)+"班级平均分"+classTotal*1.0/ary[i].length);
}
System.out.println("---------年级考试情况-------");
System.out.println("年级总分"+total+" 年级人数"+index);
System.out.println("年级平均分:"+total*1.0/index);
}

privatestaticvoidinputScore(int[][]ary){
Scannerinput=newScanner(System.in);
for(inti=0;i<ary.length;i++){
System.out.println("-------"+"班级"+(i+1)+"-------");
for(intj=0;j<ary[i].length;j++){
System.out.print("第"+(j+1)+"号的成绩:");
intscore=input.nextInt();
ary[i][j]=score;
}
}
}
}

运行测试

-------班级1-------
第1号的成绩:80
第2号的成绩:90
第3号的成绩:100
-------班级2-------
第1号的成绩:100
第2号的成绩:100
第3号的成绩:90
---------1班考试情况---------
班级总分270 班级人数3
1班级平均分90.0
---------2班考试情况---------
班级总分290 班级人数3
2班级平均分96.66666666666667
---------年级考试情况-------
年级总分560 年级人数6
年级平均分:93.33333333333333

㈣ Java二维数组输出成绩

packageclient;

importjava.awt.GridLayout;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.JButton;

importjavax.swing.JComboBox;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JPanel;

{

privateJFramejf;

privateJPaneljp;

privateJLabelname,course;

privateJComboBoxname1,course1;

privateJButtonok;

privatescoretheScore[]=newscore[3];

publicstudent(){

jf=newJFrame();

jp=newJPanel();

name=newJLabel("姓名");

course=newJLabel("科目");

jp.setLayout(newGridLayout(3,2));

StringtheName[]={"大雄","静香","康夫","all"};

StringtheCourse[]={"数学","英语","计算机","all"};

name1=newJComboBox(theName);

course1=newJComboBox(theCourse);

ok=newJButton("查询");

ok.addActionListener(this);

jp.add(name);

jp.add(name1);

jp.add(course);

jp.add(course1);

jp.add(ok);

jf.setLayout(newGridLayout(1,1));

jf.add(jp);

jf.setSize(400,150);

jf.setLocationRelativeTo(null);

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

publicvoidinputData()//输入数据

{

this.theScore[0]=newscore("大雄",10,12,15);

this.theScore[1]=newscore("静香",88,98,75);

this.theScore[2]=newscore("康夫",85,75,90);

}

publicstaticvoidmain(String[]args){

studentstu=newstudent();

stu.inputData();

}

@Override

publicvoidactionPerformed(ActionEvente){

//TODOAuto-generatedmethodstub

if(e.getSource()==ok){

Stringcontent="";

if(this.name1.getSelectedIndex()==3)//输出全部人的

{

if(this.course1.getSelectedIndex()==3)//全部分数

{

content+="姓名数学英语计算机 ";

for(inti=0;i<this.theScore.length;i++){

content+=(this.theScore[i].getName()+""

+this.theScore[i].getMath()+""

+this.theScore[i].getEnglish()+""

+this.theScore[i].getComputer()+" ");

}

JOptionPane.showMessageDialog(null,content);

return;

}else{

if(this.course1.getSelectedIndex()==0){

content+="姓名数学 ";

for(inti=0;i<this.theScore.length;i++){

content+=(this.theScore[i].getName()+""

+this.theScore[i].getMath()+" ");

}

}elseif(this.course1.getSelectedIndex()==1){

content+="姓名英语 ";

for(inti=0;i<this.theScore.length;i++){

content+=(this.theScore[i].getName()+""

+this.theScore[i].getEnglish()+" ");

}

}else{

content+="姓名计算机 ";

for(inti=0;i<this.theScore.length;i++){

content+=(this.theScore[i].getName()+""

+this.theScore[i].getComputer()+" ");

}

}

JOptionPane.showMessageDialog(null,content);

return;

}

}

//System.out.println("nameindex="+name1.getSelectedIndex()+"courseindex="+course1.getSelectedIndex());

else{

if(this.course1.getSelectedIndex()==3){

content+="姓名数学英语计算机 ";

intindex=this.name1.getSelectedIndex();

content+=(this.theScore[index].getName()+""

+this.theScore[index].getMath()+""

+this.theScore[index].getEnglish()+""

+this.theScore[index].getComputer()+" ");

JOptionPane.showMessageDialog(null,content);

return;

}else{

inti=this.name1.getSelectedIndex();

if(this.course1.getSelectedIndex()==0){

content+="姓名数学 ";

content+=(this.theScore[i].getName()+""

+this.theScore[i].getMath()+" ");

}elseif(this.course1.getSelectedIndex()==1){

content+="姓名英语 ";

content+=(this.theScore[i].getName()+""

+this.theScore[i].getEnglish()+" ");

}else{

content+="姓名计算机 ";

content+=(this.theScore[i].getName()+""

+this.theScore[i].getComputer()+" ");

}

JOptionPane.showMessageDialog(null,content);

return;

}

}

}

}

}

classscore{//保存每个人信息的类

privateStringname;

privatefloatMath;

privatefloatEnglish;

privatefloatComputer;

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicfloatgetMath(){

returnMath;

}

publicvoidsetMath(floatmath){

Math=math;

}

publicfloatgetEnglish(){

returnEnglish;

}

publicvoidsetEnglish(floatenglish){

English=english;

}

publicfloatgetComputer(){

returnComputer;

}

publicvoidsetComputer(floatcomputer){

Computer=computer;

}

publicscore(Stringname,floatMath,floatEnglish,floatComputer){

this.name=name;

this.Math=Math;

this.English=English;

this.Computer=Computer;

}

}

=================

㈤ java如何创建二维数组进行学生姓名,学号,成绩三个信息的存储,使用for循环语句进行二维数组的遍

1、分析题目,需要存储姓名学号成绩,因此,二维数组需要定义成字符串类型

姓名学号成绩
012
0[][][]
1[][][]
2[][][]

数组的每列存储内容是固定的,一行代表一个学生,遍历过程嵌套for循环就可以遍历全部学生,

intn=input;
Stringstu[][]=newString[n][2];//学生个数不定
for(inti=0;i<n;i++){
//i是行,一行就是一个“学生”,如i=0,是第一个学生
for(intj=0;j<3,j++)
{//j,是列,是每个学生的信息,0是姓名,1是学号,2是成绩
//循环过程是i=0是,遍历[0][0],[0][1],[0][2],也就依次是姓名学号成绩
System.out.print(stu[i][j]);
}
System.out.println("");//输完一个学生,换行
}

2、源代码如下

publicstaticvoidmain(Stringargs[])
{
System.out.println("请输入学生个数");
Scannerinput=newScanner(System.in);
intn=input.nextInt();
Stringstu[][]=newString[n][3];//学生个数不定
//输入信息
for(inti=0;i<n;i++){
//i是行,一行就是一个“学生”,如i=0,是第一个学生
System.out.println("请输入第"+(i+1)+"个学生的信息:");
for(intj=0;j<3;j++)
{//j,是列,是每个学生的信息,0是姓名,1是学号,2是成绩
//循环过程是i=0是,遍历[0][0],[0][1],[0][2],也就依次是姓名学号成绩
switch(j){
case0:
System.out.print("姓名:");
stu[i][j]=input.next();
break;
case1:
System.out.print("学号:");
stu[i][j]=input.next();
break;
case2:
System.out.print("成绩:");
stu[i][j]=input.next();
break;
default:
break;
}

}
}

//输出信息
for(inti=0;i<n;i++){//循环同理
for(intj=0;j<3;j++)
{//j,是列,是每个学生的信息,0是姓名,1是学号,2是成绩
//循环过程是i=0是,遍历[0][0],[0][1],[0][2],也就依次是姓名学号成绩
switch(j){
case0:
System.out.print("姓名:");
System.out.print(stu[i][j]);
break;
case1:
System.out.print("学号:");
System.out.print(stu[i][j]);
break;
case2:
System.out.print("成绩:");
System.out.print(stu[i][j]);
break;
default:
break;
}

}
System.out.println("");//输完一个学生,换行
}
}

3、运行效果如图

㈥ 用java二维数组完成两个同学三科成绩,计算每位同学的总分, 各科的平均分

简单写了下,应该符合题主的要求:

	publicstaticvoidcompute(){
版//总分
int[]sum=newint[]{0,0};
//平均分
float[]avgs=newfloat[]{0,0,0};
//两名学生的分数权
int[][]scores=newint[][]{{99,98,97},{59,60,58}};
for(inti=0;i<scores.length;i++){
for(intj=0;j<3;j++){
sum[i]+=scores[i][j];
avgs[j]+=scores[i][j];
}
}
System.out.println("学霸总分:"+sum[0]);
System.out.println("学渣总分:"+sum[1]);
System.out.print("平均分依次为:");
for(floatavg:avgs){
System.out.print(avg/2+",");
}
}

㈦ java二维数组先输入学生姓名成绩 然后再输入学生姓名提取出学生成绩

二维数组可以做,你需要去遍历,太麻烦了,
用Map 但是用map有个问题,如果是姓名重复是不能存储的(Key不能重复),所以应该用学生号来取姓名跟成绩。

㈧ java二维数组输入学生姓名输出学生成绩

二维数组可以做,你需要去遍历,太麻烦了,
用map
但是用map有个问题,如果是姓名重复是不能存储的(key不能重复),所以应该用学生号来取姓名跟成绩。

㈨ 怎样利用Java二维数组制作一个25名同学4个学科的成绩表

double[][] score = new double[4][25];
for(int i=0;i<4;i++) {
for(int j=0;j<25;j++) {
score [i][j] = 100;
System.out.print("第"+j+"个学生的第"+i+"个学科的成绩是"+score [i][j]);
}
}
大概就是这个意思,你可版以再加个存学生名权字的String数组,和存学科名字的String数组;
例如String[] studentName = new String[25];
studentName[0] = "XiaoMing";
......
String[] subjectName = new String[4];
subjectName[0] = "English";
......
System.out.print("第"+j+"个学生的第"+i+"个学科的成绩是"+score [i][j]);就可以改成
System.out.print(studentName[j]+“的"+subjectName[i]+"成绩是"+score [i][j]);

㈩ java二维数组输入学生姓名输出学生成绩

使用 java.util.Scanner scanner=new java.util.Scanner(System.in) 可以很方便接收输入

~~~~~

热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919