這里有一個(gè)類
專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、成都做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)漢源免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千余家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
實(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 Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)輸入學(xué)生的分?jǐn)?shù):");
double score = input.nextDouble();
int level1,level2;
if(score=60.0 score=100.0){
System.out.print("該學(xué)生成績?yōu)閮?yōu)秀!");
}
else if(score=0 score60.0){
System.out.print("該學(xué)生成績?yōu)椴患案瘢?);
}
else{
System.out.print("您輸入的成績有誤!");
}
}?? ?
}
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é)生的成績:");
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("總成績是" + 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é)生的成績(理論上可以輸入無限個(gè),前提是你有那么大的內(nèi)存):");
while(true){
try{
System.out.println("請(qǐng)輸入第"+count+++"個(gè)分?jǐn)?shù),或輸入ok進(jìn)行計(jì)算,離開請(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("您沒有輸入學(xué)生成績,無數(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("總成績是" + total);
System.out.println("最高分是" + max);
System.out.println("最低分是" + min);
System.out.println("平均分是" + avg);
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("輸入你的成績");
int grade = s.nextInt();
if(grade = 60grade=70){
System.out.println("及格?。。?!");
}else if(grade 70grade=85){
System.out.println("良好?。。?!");
}else if(grade 85grade=100){
System.out.println("優(yōu)秀?。。。?);
}else{
System.out.println("不及格?。。?!");
}
}
網(wǎng)頁標(biāo)題:java編寫成績的代碼 java設(shè)計(jì)學(xué)生成績管理系統(tǒng)源代碼
網(wǎng)站鏈接:http://m.rwnh.cn/article36/hpjisg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、云服務(wù)器、電子商務(wù)、關(guān)鍵詞優(yōu)化、自適應(yīng)網(wǎng)站、網(wǎng)站建設(shè)
聲明:本網(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í)需注明來源: 創(chuàng)新互聯(lián)