编写一个java成绩统计程序,输入一个班的java成绩(含姓名和分数),统计出平均分,最高分、最低分,并打印成绩单。由于编程时人数不确定,所以要求使用Vector完成上述程序。
package com.demo;import java.util.Scanner;
import java.util.Vector;class Student {
public String name;
public int score; public void setStudent(String na, int sco) {
name = na;
score = sco;
} public int getScore() {
return score;
}}public class number2 {
public static void main(String args[]) {
Vector v = new Vector();
int i;
for (i = 0;; i++) { Scanner read1 = new Scanner(System.in);
Scanner read2 = new Scanner(System.in);
String na = read2.next();
int sco = read1.nextInt();
Student s = new Student();
if (na.equals("q"))
break;
else {
s.setStudent(na, sco);
v.addElement(s);
}
}
int total = 0;
for (int j = 0; j < i; j++) {
Student s = (Student) v.elementAt(j);
total = total + s.score;
}
System.out.println("平均数为" + total / i);
int low = 100;
for (int l = 0; l < i; l++) {
Student s = (Student) v.elementAt(l);
if (low > s.getScore()) {
low = s.getScore();
}
}
System.out.println("最小的数为" + low);
int high = 0;
for (int k = 0; k < i; k++) {
Student s = (Student) v.elementAt(k);
if (high < s.getScore()) {
high = s.getScore();
}
}
System.out.println("最大的数为" + high);
}
}
package com.demo;import java.util.Scanner;
import java.util.Vector;class Student {
public String name;
public int score; public void setStudent(String na, int sco) {
name = na;
score = sco;
} public int getScore() {
return score;
}}public class number2 {
public static void main(String args[]) {
Vector v = new Vector();
int i;
for (i = 0;; i++) { Scanner read1 = new Scanner(System.in);
Scanner read2 = new Scanner(System.in);
String na = read2.next();
int sco = read1.nextInt();
Student s = new Student();
if (na.equals("q"))
break;
else {
s.setStudent(na, sco);
v.addElement(s);
}
}
int total = 0;
for (int j = 0; j < i; j++) {
Student s = (Student) v.elementAt(j);
total = total + s.score;
}
System.out.println("平均数为" + total / i);
int low = 100;
for (int l = 0; l < i; l++) {
Student s = (Student) v.elementAt(l);
if (low > s.getScore()) {
low = s.getScore();
}
}
System.out.println("最小的数为" + low);
int high = 0;
for (int k = 0; k < i; k++) {
Student s = (Student) v.elementAt(k);
if (high < s.getScore()) {
high = s.getScore();
}
}
System.out.println("最大的数为" + high);
}
}
Scanner read1 = new Scanner(System.in);
int sco = read1.nextInt();
Scanner read2 = new Scanner(System.in);
String na = read2.next();
for (int l = 0; l < i; l++) {
Student s = (Student) v.elementAt(l);
if (low > s.getScore()) {
low = s.getScore();
}
}要是所以的数都小于100,怎么算呢?
import java.util.*;
public class lianxi
{
public static void main(String[] args){
Scanner ss = new Scanner(System.in);
String [][] a = new String[5][6];
for(int i=1; i<6; i++) {
System.out.print("请输入第"+i+"个学生的学号:");
a[i-1][0] = ss.nextLine();
System.out.print("请输入第"+i+"个学生的姓名:");
a[i-1][1] = ss.nextLine();
for(int j=1; j<4; j++) {
System.out.print("请输入该学生的第"+j+"个成绩:");
a[i-1][j+1] = ss.nextLine();
}
System.out.println("\n"); }//
以下计算平均分float avg;int sum;
for(int i=0; i<5; i++) {
sum=0;
for(int j=2; j<5; j++) {
sum=sum+ Integer.parseInt(a[i][j]); }
avg= (float)sum/3;
a[i][5]=String.valueOf(avg);}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;public class Csdn_num { /**
* @param args
* @throws IOException
*/
@SuppressWarnings({ "null", "unused" })
int average ;
int max;
int min;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int n=0;
BufferedReader buf_n=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请你输入要录入成绩的学生个数");
n=Integer.parseInt(buf_n.readLine());
int num[] = new int[n];
String name[] = new String[n];
BufferedReader buf[] =new BufferedReader[n];
BufferedReader buf_num[] =new BufferedReader[n] ;
System.out.println("请根据提示输入数据");
for(int i=0;i<buf.length;i++){
System.out.println("请输入"+"第"+i+"个学生信息");
System.out.println("请输入学生姓名");
buf[i]=new BufferedReader(new InputStreamReader(System.in));
name[i]=buf[i].readLine();
System.out.println(name[i]+"的成绩是");
buf_num[i]=new BufferedReader(new InputStreamReader(System.in));
num[i]=Integer.parseInt(buf_num[i].readLine());
}
System.out.println("数据录入工作结束,下面是统计结果");
Csdn_num csdn=new Csdn_num();
csdn.average(num);
csdn.max(num);
csdn.min(num);
}
public void average(int num[]){
int sum = 0;
for(int i=0;i<num.length;i++){
sum+=num[i];
}
average=sum/num.length;
System.out.println("平均值为:"+average);
}
public void max(int num[]){
Arrays.sort(num);
System.out.println("最大值为:"+num[num.length-1]);
}
public void min(int num[]){
Arrays.sort(num);
System.out.println("最小值为:"+num[0]);
}
}