JAVA语言程序设计(基础篇) 第十版——第七章 一维数组 (参考答案)

这篇博客详细介绍了JAVA一维数组的编程练习,涵盖7.2至7.12节的内容,包括计算数字出现次数、分析成绩、打印不同数、求平均值、找最小元素及其下标、计算标准差和倒置数组等题目。博主分享了自己的解题思路,并引用了其他大神的解决方案。
摘要由CSDN通过智能技术生成

(7.2~7.5节)+(7.6~7.8节)+7.9节+(7.10~7.12节)

我只做到了21题,有点乏了,未完待续.........(以后更新)

(7.2~7.5节)

*7.1(指定等级)

import java.util.Scanner;

public class S1 {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.print("Enter the number of students: ");
		int numbers=input.nextInt();
		System.out.print("Enter "+numbers+" scores: ");
		
		int[] scores=new int[numbers];
		for(int i=0; i<scores.length; i++) {
			scores[i]=input.nextInt();
		}
		
		int best=scores[0];
		for(int i=1; i<scores.length; i++) {
			if(best<scores[i])
				best=scores[i];
		}
		
		char[] ch= {'A','B','C','D','E','F'};
		
		for(int i=0; i<scores.length; i++) {
			if(scores[i]>=best-10)
				System.out.println("Student "+i+" score is "+scores[i]+" and grade is "+ch[0]);  
			else if(scores[i]>=best-20)
				System.out.println("Student "+i+" score is "+scores[i]+" and grade is "+ch[1]);  
			else if(scores[i]>=best-30)
				System.out.println("Student "+i+" score is "+scores[i]+" and grade is "+ch[2]); 
			else if(scores[i]>=best-40)
				System.out.println("Student "+i+" score is "+scores[i]+" and grade is "+ch[3]);  
			else
				System.out.println("Student "+i+" score is "+scores[i]+" and grade is "+ch[4]);  
		}
		
		input.close();
	}	
}

7.2(倒置输入的数)

import java.util.Scanner;

public class S2 {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.print("请输入10个整数: ");
		
		int[] numbers=new int[10];
		for(int i=0; i<numbers.length; i++) {
			numbers[i]=input.nextInt();
		}
		
		for(int i=numbers.length-1; i>=0; i--) {
			System.out.print(" "+numbers[i]);
		}
		
		
		input.close();
	}

}

**7.3(计算数字出现的次数)

参考大神博客会有不同解法:

https://blog.csdn.net/weixin_46215617/article/details/105097958?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

https://blog.csdn.net/LEE_FIGHTING_JINGYU/article/details/80009407?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

在这里我用count[1]存储数字1的次数,用count[2]存储数字2的次数,......,以此类推。

import java.util.Scanner;

public class S3 {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.print("Enter tne integers between 1 and 100: ");
		
		int number=input.nextInt();
		int[
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值