JAVA从入门到精通------基础篇------学生管理系统


import java.util.Scanner;

public class Student {
	public static void main(String[] args) {
		//写一个Scanner流用来在控制台输入
		Scanner input = new Scanner(System.in);
		
		//定义一个数组存学生的成绩
		int[] score = new int[5];
		
		System.out.println("-----------------------");
		System.out.println("------学生管理系统------");
		System.out.println("-----------------------");
		System.out.println("");
		System.out.println("");
		
		//定义一个char类型的newInput变量接收y还是n
		char newInput='y';
		
		do {
			
			System.out.println("录入学生成绩 " + "\t" + "选择1");
			System.out.println("获取最高成绩" + "\t" + "选择2");
			System.out.println("获取平均分" + "\t" + "选择3");
			System.out.println("修改成绩 " + "\t" + "选择4");
			System.out.println("查询成绩    " + "\t" + "选择5");
			System.out.println();
			System.out.println("请输入您的选项");
			
			//输入num用来选择菜单
			int num = input.nextInt();
			
			
			
			switch(num){
		    
		    case 1:
		    	scannerScore(score);
		    	break;
		    case 2:
		    	System.out.println("最高成绩为:" + max(score));
		    	break;
		    case 3:
		    	System.out.println("平均分为:" + avg(score));
		    	break;
		    case 4:
		    	newScore(score);
		    	break;
		    case 5:
		    	traverseScore(score);
		    	break;
		    default :
		    	System.out.println("输入错误请您重新输入");
		    	
		    }
	    
	    
	    
			//先写话再输入y/n
		System.out.println("是否需要选择其他功能,如果需要请输入y退出请按n");
	    newInput = input.next().charAt(0);
	    
		}while(newInput == 'y');
		
		
			System.out.println("感谢您使用本系统!");
		
	}
	
	
	
	public static void scannerScore(int[] array) {
		//写一个输入流
		Scanner input = new Scanner(System.in);
		
		for(int i=0;i<array.length;i++) {
			System.out.println("请您输入第" + (i+1) + "名学生的成绩");
			array[i] = input.nextInt();
		}
		
	}
	
	
	
	public static int max(int[] array) {
		int max = array[0];
		
		for(int i=0;i<array.length;i++) {
			if(max<array[i]) {
			max = array[i];	
			}
		}
		return max;
	}
	
	
	
	public static int avg(int[] array) {
		int sum = 0;
		int avg = 0;
		for(int i=0;i<array.length;i++) {
			sum += array[i];
		}
		avg = sum/array.length;
		return avg;
	}
	
	
	
	public static void newScore(int[] array) {
		Scanner input = new Scanner(System.in);
		
		System.out.println("请输入要改第几名同学的成绩");
		int num = input.nextInt();
		System.out.println("该同学的成绩为多少");
		int score1 = input.nextInt();
		
		array[num-1]=score1;
	}
	
	
	
	public static void traverseScore(int[] array) {
		for(int i=0;i<array.length;i++) {
			System.out.println("第" + (i+1) +"个学生的成绩为:" + array[i]);
		}
	}
	
	
	
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值