数组要稍微该一下......然后用swing
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class JTableTest
{
public JTableTest()
{
JFrame f=new JFrame();
String [] Names = {"姓名","语文","数学","英语","物理","计算机"};
Object[][] playerInfo=
{{"张三",78,87,85,91,79},
{"李四",82,82,85,91,79},
{"王五",77,89,77,80,89},
{"赵六",69,76,87,80,90}};
JTable table=new JTable(playerInfo,Names);
table.setPreferredScrollableViewportSize(new Dimension(550,100));
JScrollPane scrollPane=new JScrollPane(table);
f.getContentPane().add(scrollPane,BorderLayout.CENTER);
f.setTitle("test window");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
public static void main(String[] args)
{
new JTableTest ();
}
}
代码如下:
---------------------------------
public class Score {
public static void main(String[] args) {
String[] student = { "张三", "李四", "王五", "赵六" };
String[] course = { "语文", "数学", "英语", "物理", "计算机" };
int[][] score = { { 78, 87, 85, 91, 79 }, { 82, 82, 85, 91, 79 },
{ 77, 89, 77, 80, 89 }, { 69, 76, 87, 80, 90 } };
int[] are = new int[course.length];
System.out.print("\t");
for (int i = 0; i < course.length; i++) {
System.out.print(course[i] + "\t");
}
System.out.println("个人平均分\t");
for (int i = 0; i < student.length; i++) {
System.out.print(student[i] + "\t");
int count = 0;
for (int j = 0; j < score[i].length; j++) {
System.out.print(score[i][j] + "\t");
are[j] += score[i][j];
count += score[i][j];
}
System.out.print((count / (score[i].length * 1.0)) + "\t");
System.out.println();
}
System.out.print("各科平均\t");
for (int i = 0; i < are.length; i++) {
System.out.print((are[i] / (student.length * 1.0)) + "\t");
}
}
}
运行结果:
---------------------------
语文数学英语物理计算机个人平均分
张三788785917984.0
李四828285917983.8
王五778977808982.4
赵六697687809080.4
各科平均76.583.583.585.584.25
这个是很简单的基础问题了