栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

一维数组的使用,学生成绩的分级,和求最大值

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一维数组的使用,学生成绩的分级,和求最大值

package com.day1.Contacts;
import java.util.Scanner;
public class Arry3Test { public static voidmain(String[] args) {
Scanner scanner=new Scanner(System.in);
//use scnner to import student number
// 译文(使用scanner导入学生人数) System.out.println(“请输入人数”);
int number1 = scanner.nextInt();
int[] scores = new int[number1];
// create array ,use Scanner to import student scores;dynamic initialization
// 译文(创建数组,使用scanner导入学生成绩,动态初始化)
for (int i=0;i // use the for statement to maximize the scores.
// 译文(使用for语句求最大成绩)
int a=scores[0]; for (int i =0;i if (scores[i+1]>scores[i]) { a=scores[i+1]; } } System.out.println(“The highest score is”+a);
// nexted if statements in the for statement,scores all gredes.
// 译文(在for语句中嵌套if语句,堆成绩进行分等级)
for (int j=0;j if(scores[j]>=a-10) { System.out.println(“student”+j+" the scores is"+scores[j]+“grade is A”); }
else if(scores[j]>=a-20) { System.out.println(“student”+j+" the scores is"+scores[j]+“grade is B”); }
else if(scores[j]>=a-30) { System.out.println(“student”+j+" the scores is"+scores[j]+“grade is C”); }
else { System.out.println(“student”+j+" the scores is"+scores[j]+“grade is D”); } } }}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/606448.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号