利用java基础语句实现学生成绩录入,并求其成绩平均值

c40e272a36cf4d5ab7f9249cde6f2d5a.png

上图为实现效果

默认定义成绩表的长度为10。

import java.util.Scanner;public class pingjunfen {  

static int a = 10;    

static int num[] = new int[a];    

static String name[] = new String[a];    

static double a1[] = new double[a];    

static double a2[] = new double[a];    

static double a3[] = new double[a];    

static double average[] = new double[a];   static int h;    

public void pr(){        

for(h=0;h<=a;h++){        

average[h] = (a1[h]+a2[h]+a3[h])/3;        System.out.println("|  "+num[h]+"\t"+" | "+"\t"+name[h]+"\t"+" | "+"\t"        +a1[h]+"\t"+" | "+"\t"+a2[h]+"\t"+" | "+"\t"+a3[h]+"\t"+" | "+"\t   "        +average[h]+"\t"+"  |");        System.out.println("-------------------------------------"+        "------------------------------------------------------");}    

}  

 public static void main(String[] args) {        Scanner key = new Scanner(System.in);        pingjunfen h1 = new pingjunfen();        

while (true) {                        

for(int h=0;h<=a;h++){              

 if(h==a){            

System.out.println("表格存储已达上限!!!");                

break;                 }        

System.out.println("请输入你的学号");        num[h] = key.nextInt();        System.out.println("请输入你的姓名");        name[h] = key.next();        System.out.println("请输入你的语文成绩");        a1[h] = key.nextDouble();        System.out.println("请输入你的数学成绩");        a2[h] = key.nextDouble();        System.out.println("请输入你的英语成绩");        a3[h] = key.nextDouble();                System.out.println("1.继续添加  2.退出");        int choice = key.nextInt();          

 if (choice==1);            

else if (choice==2)                

break;               

else            

System.out.println("输入非法,请重新输入");        }        

System.out.println("-------------------------------------"+        "------------------------------------------------------");        System.out.println("|                             "+        ">>>>>>>>学生成绩表<<<<<<<<                                  |");        

System.out.println("-------------------------------------"+        "------------------------------------------------------");        System.out.println("|  学号"+"\t"+" | "+"\t"+"姓名"+"\t"+" | "+"\t"+        "语文"+"\t"+" | "+"\t"+"数学"+"\t"+" | "+"\t"+"英语"+"\t"+" | "+"\t"        +"平均成绩  |");        System.out.println("-------------------------------------"+        "------------------------------------------------------");        h1.pr();        

break;    }

}

}

  • 14
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值