import java.util.Scanner;

成都創(chuàng)新互聯(lián)2013年開(kāi)創(chuàng)至今,先為武隆等服務(wù)建站,武隆等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為武隆企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
public class test {
static int s;
public static void main(String[] argv) {
int [] num=new int[20];
Scanner scanner=new Scanner(System.in);
Integer a;
int i;
for(i=1;i=20;i++){
System.out.println("請(qǐng)輸入第"+i+"一個(gè)分?jǐn)?shù)(結(jié)束請(qǐng)輸入520嘿嘿):");
a=scanner.nextInt();
num[i-1]=a;
if(a==520){
break;
}
}
for(int m=0;mi-1;m++)
{
s=s+num[m];
}
System.out.println("總共錄入了"+(i-1)+"個(gè)分?jǐn)?shù)");
System.out.println("總成績(jī)是"+s+"分");
System.out.println("平均分是"+s/(i-1)+"分");
for(Integer m=0;mnum.length-1;m++)
{ if(num[m]0num[m]!=520){
if(num[m]=90)
System.out.println(num[m]+"優(yōu)秀");
else if(num[m]=80)
System.out.println(num[m]+"良好");
else if(num[m]=70)
System.out.println(num[m]+"中等");
else if(num[m]=60)
System.out.println(num[m]+"及格");
else
System.out.println(num[m]+"不及格");
}else break;
}
}
}
我的代碼很簡(jiǎn)潔,采納我唄。。。
import?java.util.Scanner;
public?class?Test?{
protected?static?boolean?end_flag?=?true;
public?static?void?main(String[]?args)?{
Students?student?=?new?Students();
student.InputData();//?輸入學(xué)生數(shù)據(jù)
String?order;
while?(end_flag)?{
System.out.println("請(qǐng)輸入數(shù)字1-5:");
Scanner?s?=?new?Scanner(System.in);
order?=?s.nextLine();
student.Operator(order);
}
}
}
Students類:
import?java.util.ArrayList;
import?java.util.Scanner;
public?class?Students?{
private?int?STUDENTS_NUM?=?5;?//?學(xué)生的人數(shù)
private?int?SUBJECTS_NUM?=?3;?//?課程數(shù)
private?String[][]?data?=?new?String[STUDENTS_NUM][SUBJECTS_NUM?+?2];
private?String?name;
private?int?Chinese_score;
private?int?Math_score;
private?int?English_score;
public?void?SearchHighestScore(String[][]?original)?{?//?查找最高成績(jī)
int?flag?=?Integer.parseInt(original[0][4]),?position?=?0;
for?(int?i?=?1;?i??original.length;?i++)?{
if?(Integer.parseInt(original[i][4])??flag)?{
flag?=?Integer.parseInt(original[i][4]);
position?=?i;
}
}
System.out.print("最高分同學(xué)的姓名和總分為:");
System.out.println(original[position][0]?+?"?"?+?original[position][4]);
}
public?void?SearchLowestScore(String[][]?original)?{
int?flag?=?Integer.parseInt(original[0][4]),?position?=?0;
for?(int?i?=?1;?i??original.length;?i++)?{
if?(Integer.parseInt(original[i][4])??flag)?{
flag?=?Integer.parseInt(original[i][4]);
position?=?i;
}
}
System.out.print("最低分同學(xué)的姓名和總分為:");
System.out.println(original[position][0]?+?"?"?+?original[position][4]);
}
public?void?OrderStudents(String[][]?original)?{
String[][]?result?=?original;
String?temp;
for?(int?i?=?1;?i??result.length;?i++)?{
for?(int?j?=?0;?j??result.length?-?i;?j++)?{
if?(Integer.parseInt(result[j][4])??Integer
.parseInt(result[j?+?1][4]))?{
temp?=?result[j][4];
result[j][4]?=?result[j?+?1][4];
result[j?+?1][4]?=?temp;
temp?=?result[j][0];
result[j][0]?=?result[j?+?1][0];
result[j?+?1][0]?=?temp;
}
}
}
System.out.println("排名\t"?+?"姓名\t"?+?"總分\t");
for?(int?i?=?0;?i??STUDENTS_NUM;?i++)?{
System.out.println(i?+?1?+?"\t"?+?result[i][0]?+?"\t"
+?result[i][4]);
}
}
public?void?ScoreUnder60(String[][]?original)?{
System.out.println("平均分在60以下的學(xué)生的姓名為:");
ArrayList?temp?=?new?ArrayList();
for?(int?i?=?0;?i??original.length;?i++)?{
if?(Integer.parseInt(original[i][4])?/?SUBJECTS_NUM??60)?{
temp.add(original[i][0]);
}
}
System.out.print(temp?+?"?");
System.out.println("\n"?+?"平均分在60以下的學(xué)生的人數(shù)為:"
+?temp.size());
}
public?Integer?SearchScore(String?student_name)?{
int?position?=?-1;
for?(int?i?=?0;?i??data.length;?i++)?{
if?(student_name.equals(data[i][0]))?{
position?=?i;
}
}
if?(position?!=?-1)
return?Integer.valueOf(data[position][4]);
else
return?null;
}
public?void?Operator(String?order)?{
if?("1".equals(order))?{
SearchHighestScore(data);
SearchLowestScore(data);
}?else?if?("2".equals(order))?{
OrderStudents(data);
}?else?if?("3".equals(order))?{
ScoreUnder60(data);
}?else?if?("4".equals(order))?{
String?name;
System.out.println("請(qǐng)輸入學(xué)生的姓名:");
Scanner?s?=?new?Scanner(System.in);
name?=?s.nextLine();
if?(SearchScore(name)?!=?null)
System.out.println(name?+?"的總分為:"?+?SearchScore(name));
else
System.out.println("查無(wú)此人");
}?else?if?("5".equals(order))?{
Test?obj?=?new?Test();
obj.end_flag?=?false;
System.out.println("退出");
}?else?{
System.out.println("輸入有誤!");
}
}
public?void?InputData()?{
for?(int?i?=?1;?i?=?STUDENTS_NUM;?i++)?{
System.out.print("請(qǐng)輸入第"?+?i?+?"個(gè)人的姓名"?+?":");
Scanner?s1?=?new?Scanner(System.in);
name?=?s1.nextLine();
data[i?-?1][0]?=?name;
System.out.print("請(qǐng)輸入第"?+?i?+?"個(gè)人的語(yǔ)文成績(jī)"?+?":");
Scanner?s2?=?new?Scanner(System.in);
Chinese_score?=?s2.nextInt();
data[i?-?1][1]?=?String.valueOf(Chinese_score);
System.out.print("請(qǐng)輸入第"?+?i?+?"個(gè)人的數(shù)學(xué)成績(jī)"?+?":");
Scanner?s3?=?new?Scanner(System.in);
Math_score?=?s3.nextInt();
data[i?-?1][2]?=?String.valueOf(Math_score);
System.out.print("請(qǐng)輸入第"?+?i?+?"個(gè)人的英語(yǔ)成績(jī)"?+?":");
Scanner?s4?=?new?Scanner(System.in);
English_score?=?s4.nextInt();
data[i?-?1][3]?=?String.valueOf(English_score);
data[i?-?1][4]?=?String.valueOf(Chinese_score?+?Math_score
+?English_score);
System.out.println(data[i?-?1][4]);
}
}
}
給你一點(diǎn)思路。
1、成績(jī)單類、班級(jí)類、學(xué)生類、課程類。
其中成績(jī)單中有其它類對(duì)象,班級(jí)類中有學(xué)生對(duì)象,學(xué)生類中有課程對(duì)象。分別用Vector 或者ArrayList存放對(duì)象。
2、序列化所有對(duì)象保存到文件中。但是這樣只能從從程序中存入文件,打開(kāi)文件則是亂碼顯示。所以還是用數(shù)據(jù)庫(kù)比較好。建立4張表,存放相應(yīng)的信息,再對(duì)其進(jìn)行SQL操作。
3、就是對(duì)數(shù)據(jù)一系列查詢、插入、修改和刪除操作。建議用Vector存放對(duì)象操作比較方便。
1、編寫一個(gè)java成績(jī)統(tǒng)計(jì)程序,輸入一個(gè)班的java成績(jī)(含姓名和分?jǐn)?shù)),統(tǒng)計(jì)出平均分,最高分、最低分,并打印成績(jī)單。由于編程時(shí)人數(shù)不確定,所以要求使用Vector或ArrayList完成上述程序。1)學(xué)生成績(jī)用一個(gè)類Mark表示,其成員變量包含考生姓名、成績(jī)。輸入的姓名為"end"時(shí),程序結(jié)束。
2、主類的名稱叫做GradeStatistic,將Mark設(shè)計(jì)為GradeStatistic的內(nèi)部類。提示:鍵盤輸入采用Scanner類,實(shí)例化Scanner采用下述語(yǔ)句:Scanner sc=new Scanner(System.in);然后通過(guò)sc調(diào)
我寫了一個(gè),符合你的要求不?
import java.util.Scanner;
public class Score {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
double score;
int num=10;//錄入分?jǐn)?shù)個(gè)數(shù)
for(int i=0;inum;i++){
String s = scanner.next();
try{
score=Double.parseDouble(s);
printInfo(score);
}catch(NumberFormatException e){
i--;
System.out.println("你輸入有誤,請(qǐng)輸入數(shù)字");
}
}
}
public static void printInfo(double score){
if(score100||score0)
System.out.println("分?jǐn)?shù)輸入錯(cuò)誤");
else if(score=90)
System.out.println("A");
else if(score=80)
System.out.println("B");
else if(score=70)
System.out.println("C");
else if(score=60)
System.out.println("D");
else
System.out.println("E");
}
}
public static void main(String[] args) {
double scores[] = new double[5];
double total = 0;
double avg = 0;
double max = 0;
double min = 0;
int count=0;
String inputStr=null;
System.out.println("請(qǐng)輸入5名學(xué)生的成績(jī):");
Scanner input = new Scanner(System.in);
while(count5){
try{
if(count 5){
System.out.println("請(qǐng)輸入第"+(count+1)+"個(gè)分?jǐn)?shù):");
}
inputStr=input.nextLine();
scores[count++]=Double.valueOf(inputStr.trim());
}catch(Exception e){
if(inputStr!=null "exit".equals(inputStr.trim())){
System.out.println("您已成功結(jié)束程序");
System.exit(0);
}
System.out.println("若想結(jié)束請(qǐng)輸入:exit");
System.out.print("您輸入的分?jǐn)?shù)不是數(shù)值類型,");
count--;
}
}
input.close();
Arrays.sort(scores);
min=scores[0];
max=scores[scores.length-1];
for(double score :scores){
total += score;
}
avg=total/scores.length;
System.out.println("總成績(jī)是" + total);
System.out.println("最高分是" + max);
System.out.println("最低分是" + min);
System.out.println("平均分是" + avg);
}
//-------------------------------------------------------------------------
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while(true){
Double[] scores = null;
double total = 0;
double avg = 0;
double max = 0;
double min = 0;
int count=1;
ListDouble inputScores=new ArrayListDouble();
String inputStr=null;
System.out.println("請(qǐng)輸入要統(tǒng)計(jì)學(xué)生的成績(jī)(理論上可以輸入無(wú)限個(gè),前提是你有那么大的內(nèi)存):");
while(true){
try{
System.out.println("請(qǐng)輸入第"+count+++"個(gè)分?jǐn)?shù),或輸入ok進(jìn)行計(jì)算,離開(kāi)請(qǐng)輸入exit");
inputStr=input.nextLine();
inputScores.add((double)Double.valueOf(inputStr.trim()));
}catch(Exception e){
if(inputStr!=null "exit".equals(inputStr.trim().toLowerCase())){
System.out.println("您已成功結(jié)束程序");
input.close();
System.exit(0);
}
if(inputStr!=null "ok".equals(inputStr.trim().toLowerCase())){
break;
}
System.out.println("您輸入的分?jǐn)?shù)不是數(shù)值類型,");
System.out.println("若想結(jié)束請(qǐng)輸入exit ,若想計(jì)算結(jié)果請(qǐng)輸入ok");
count--;
}
}
if(inputScores.size()==0){
System.out.println("您沒(méi)有輸入學(xué)生成績(jī),無(wú)數(shù)據(jù)可統(tǒng)計(jì),程序結(jié)束。");
return ;
}
scores=inputScores.toArray(new Double[inputScores.size()]);
Arrays.sort(scores);
min=scores[0];
max=scores[scores.length-1];
for(double score :scores){
total += score;
}
avg=total/scores.length;
System.out.println("總成績(jī)是" + total);
System.out.println("最高分是" + max);
System.out.println("最低分是" + min);
System.out.println("平均分是" + avg);
}
}
分享文章:java分析成績(jī)單代碼,java成績(jī)統(tǒng)計(jì)
瀏覽路徑:http://chinadenli.net/article12/dsesegc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、域名注冊(cè)、網(wǎng)站收錄、手機(jī)網(wǎng)站建設(shè)、小程序開(kāi)發(fā)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)