(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[i]=input.nextInt();
}
int best=scores[0];
for(int i=1; i
if(best
best=scores[i];
}
char[] ch= {‘A’,’B’,’C’,’D’,’E’,’F’};
for(int i=0; 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[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[] counts=new int[102];
int i=1;
while(number!=0) {
if(number>=1 && number<=100) {
counts[number]++;
}
number=input.nextInt();
}
for(int j=1; j<=100; j++) {
if(counts[j]>0) {
System.out.println(j+” occurs “+counts[j]+(counts[j]>1 ? ” times.” :” time.”));
}
}
input.close();
}
}
7.4(分析成绩)
今天的文章Java语言程序设计答案王振飞_JAVA语言程序设计(基础篇) 第十版——第七章 一维数组 (参考答案)…分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/61227.html