java 二维数组 输出 在线等~

2024-11-26 10:26:49
推荐回答(4个)
回答1:

import java.util.HashMap;

public class Stu
{
public static void main(String [] args)
{
int a[][]=new int[5][3];
a[0][0]=1;
a[0][1]=91;
a[0][2]=96;
a[1][0]=2;
a[1][1]=78;
a[1][2]=58;
a[2][0]=3;
a[2][1]=59;
a[2][2]=78;
a[3][0]=4;
a[3][1]=89;
a[3][2]=95;
a[4][0]=5;
a[4][1]=80;
a[4][2]=85;
HashMap map=new HashMap();
map.put(1,"学生1");
map.put(2,"学生2");
map.put(3,"学生3");
map.put(4,"学生4");
map.put(5,"学生5");
for(int i=0;i<5;i++)
{
System.out.print(map.get(a[i][0])+" ");

for(int j=1;j<3;j++)
{

System.out.print(a[i][j]);
if(j!=2)System.out.print(" ");
}
System.out.println();
}

}
}

回答2:

public class Test {
public static void main(String[] args) {
int[][] score = new int[][] { { 91, 96 }, { 78, 58 }, { 59, 78 },
{ 89, 95 }, { 80, 85 } };
System.out.println("学生\t语文\t数学");
for (int i = 0; i < 5; i++) {
System.out.print("学生" + (i + 1) + "\t");
for (int j = 0; j < 2; j++) {
System.out.print(score[i][j] + "\t");
}
System.out.print("\n");
}
}
}

回答3:

public class Test {
public static void main(String [] args){
int [] []student={{99,96},{78,58},{59,78},{89,95},{80,85}};
System.out.println("学生 语文 数学");
for(int i=0;i System.out.print("学生"+(i+1)+" ");
for(int j=0;j System.out.print(student[i][j]+" ");
}
System.out.println();
}

}

}

回答4:

public class TestArray{
public static void main(String[] args) {
String[][] arr={{"91,96"},{"78,58"},{"59,78"},{"89,95"},{"80,85"}};
for(int i=0;i for(int j=0;j System.out.print("学生"+i+"成绩"+arr[i][j]+" ");
}
System.out.println();
}
}
}