(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(计算数字出现的次数)
参考大神博客会有不同解法:
在这里我用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[