現(xiàn)在的大學(xué)考試題目果然簡單了阿
創(chuàng)新互聯(lián)公司自2013年起,先為通道等服務(wù)建站,通道等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為通道企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
1,做個(gè)循環(huán)一次錄入10人成績,存入相應(yīng)list或者數(shù)組
2,計(jì)算
3,輸入姓名,可以用map實(shí)現(xiàn),或者簡單的遍歷數(shù)組或者list
1、題目描述:
/*java編程:輸入某個(gè)班學(xué)生的成績,輸入-1時(shí),表示輸入結(jié)束。計(jì)算該班的學(xué)生人數(shù)、最高分、最低分和平均分*/
分析:
根據(jù)題目可知,①需要連續(xù)輸入數(shù)據(jù),并將連續(xù)輸入的數(shù)據(jù)保存,②記錄輸入的數(shù)據(jù)個(gè)數(shù)③需要有輸入數(shù)據(jù)內(nèi)容判斷,如果輸入-1則停止輸入,執(zhí)行計(jì)算。
2、代碼如下
public?static?void?main(String[]?args)?{
ArrayListFloat?gList=new?ArrayList();//定義浮點(diǎn)型動(dòng)態(tài)數(shù)組,用作記錄成績,也可以取數(shù)組長度作為人數(shù)
Scanner?input?=new?Scanner(System.in);
float?grade=0;
?for?(?;grade!=-1;??)?{//當(dāng)輸入-1時(shí)結(jié)束
?System.out.println("請(qǐng)輸入學(xué)生成績(-1結(jié)束輸入):");
?grade=input.nextFloat();
?if?(grade!=-1)?{//避免最后一次錄入-1
?gList.add(grade);
}
}
//當(dāng)輸入-1時(shí)停止記錄數(shù)據(jù)
?
?
//求最高分
//最低分
float?max=0,sum=0,aveg=0;
float?min=gList.get(0);//取第一項(xiàng)作為最低分初始值
for?(int?i?=?0;?i??gList.size();?i++)?{
if?(maxgList.get(i))?{
max=gList.get(i);
}
if?(mingList.get(i))?{
min=gList.get(i);
}
sum+=gList.get(i);//求總分
}
//平均分
aveg=sum/gList.size();
System.out.println("共有?"+gList.size()+"人,"+"最高分:"+max
+",最低分:"+min+",平均分:"+aveg);
}
3、運(yùn)行效果
Java學(xué)生成績管理系統(tǒng)源代碼:
import Java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
/*
* Created on 2005-1-11
*/
/**
* @author 讓煒
* @since 1.0
*
* TODO 學(xué)生成績治理系統(tǒng)
* 通過學(xué)號(hào)查找,修改,刪除數(shù)據(jù)
*
*/
public class LittleProgram
{
static boolean isDelete = true;
static boolean isFind = true;
public static void main(String [] args)//主方法,程序從這里開始運(yùn)行
throws IOException,NumberNotFoundException
{
int choice=-1;
do{
LittleProgram lp = new LittleProgram();
System.out.println();
System.out.println("\t####################################");
System.out.println();
System.out.println("\t\t Java學(xué)生成績治理系統(tǒng)1.1");
System.out.println("\t\t請(qǐng)用學(xué)號(hào)查找,修改,刪除數(shù)據(jù)");
System.out.println();
System.out.println("\t####################################\n");
System.out.print("1.增加數(shù)據(jù):\n"+
"2.查找數(shù)據(jù):\n"+
"3.刪除數(shù)據(jù):\n"+
"4.清除所有數(shù)據(jù):\n"+
"5.把數(shù)據(jù)全部打印到屏幕\n"+
"6.把成績按學(xué)號(hào)排序\n"+
"7.修改數(shù)據(jù)\n"+
"8.統(tǒng)計(jì)已記錄成績學(xué)生數(shù)\n"+
"9.關(guān)于作者\(yùn)n"+
"0.退出程序.\n" +
"輸入:");
BufferedReader in = //從終
new BufferedReader( //端接
new InputStreamReader(System.in));//收數(shù)
String inputLine = in.readLine(); //字選
choice= Integer.valueOf(inputLine).intValue();//項(xiàng);
switch(choice)
{
case 1: {//1.增加數(shù)據(jù)
String str = lp.inputData();
lp.addData(str);
System.out.println("增加數(shù)據(jù)成功.");
timeOut(1);
}break;
case 2: {//2.查找數(shù)據(jù)
long find = 0;
資料引用:
這里有一個(gè)類
實(shí)現(xiàn)學(xué)生學(xué)號(hào),數(shù)學(xué),語文,英語成績錄入
并且計(jì)算平均成績,按照平均成績高低輸出信息
你可以改改!
//實(shí)現(xiàn)簡單的學(xué)生信息輸入輸出和初步的成績排序
public
class
student
{
private
int
id;
//學(xué)號(hào)
private
int
mathscore;
//數(shù)學(xué)成績
private
int
chinscore;
//語文成績
private
int
forescore;
//外語成績
public
student()
{
id
=
0;
mathscore
=
0;
chinscore
=
0;
forescore
=
0;
}
public
student(int
newid,
int
newmathscore,
int
newchinsvore,
int
newforescore)
{
id
=
newid;
mathscore
=
newmathscore;
chinscore
=
newchinsvore;
forescore
=
newforescore;
}
public
double
getaveragescore()
{
//求平均成績
double
averagescore
=
((double)
mathscore
+
chinscore
+
forescore)
/
3;
return
averagescore;
}
public
void
output(student
student)
{
//輸出對(duì)象的內(nèi)容
system.out.println("
"
+
student.id
+
"
"
+
student.mathscore
+
"
"
+
student.chinscore
+
"
"
+
student.forescore
+
"
"
+
student.getaveragescore());
}
public
int
max(student
a[],
int
n)
{
//student類對(duì)象數(shù)組的前n項(xiàng)中的成績最大值的索引
int
position
=
0;
for
(int
i
=
1;
i
n;
i++)
{
if
(a[i].getaveragescore()
a[position].getaveragescore())
{
//比較平均成績
position
=
i;
}
}
return
position;
}
public
void
selectsort(student
a[])
{
//student類對(duì)象數(shù)組的選擇排序
for
(int
n
=
a.length;
n
1;
n--)
{
int
i
=
max(a,
n);
student
temp
=
a[i];
a[i]
=
a[n
-
1];
a[n
-
1]
=
temp;
}
}
}
import java.util.Scanner;
public class Student{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("請(qǐng)輸入學(xué)生的人數(shù)....");
int num = sc.nextInt();
int[] arr = new int[num];
double[] chengji_arr = new double[num]; //存放成績的
String[] String_arr = new String[num]; //存放姓名的
String chengjis = "";
String names = "";
for(int i = 0; i arr.length i String_arr.length i chengji_arr.length; i++){
arr[i] = i;
int s = 0;
Students st = new Students();
System.out.println("請(qǐng)輸入第"+(arr[i]+1)+"個(gè)學(xué)生的序號(hào)!");
st.setId(sc.nextInt());
System.out.println("請(qǐng)輸入第"+(arr[i]+1)+"個(gè)學(xué)生的姓名!");
st.setName(sc.next());
System.out.println("請(qǐng)輸入第"+(arr[i]+1)+"個(gè)學(xué)生的成績!");
st.setChengji(sc.nextDouble());
String_arr[i] = st.getName(); //保存成績
chengji_arr[i] = st.getChengji();
}
int max = 0;
int tmp = 0;
for (int i = 0; i chengji_arr.length; i++) {
max = i;
for (int j = i + 1; j chengji_arr.length; j++) {
if (chengji_arr[max] chengji_arr[j])
max = j;// 記下較大數(shù)位置,再次比較,直到最大
}
if (i != max) {
tmp = (int)chengji_arr[i];
chengji_arr[i] = chengji_arr[max];
chengji_arr[max] = tmp;
}
}
for (int i = 0; i chengji_arr.length; i++)
System.out.print("成績?yōu)椋?+chengji_arr[i] + " ");
}
}
class Students{
private int id;
private String name;
private double chengji;
public void setId(int id){
this.id = id;
}
public int getId(){
return id;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setChengji(double chengji){
this.chengji = chengji;
}
public double getChengji(){
return chengji;
}
}
//代碼沒有交換學(xué)生數(shù)組下標(biāo),麻煩提問者再修改一下吧,真的要睡了,明天繼續(xù)上班,抱歉,只能幫你到這里了。