Java语言程序设计与数据结构(基础篇)第七章答案
答案为本人求解,如有错误,还望海涵。如有雷同,纯属巧合。
7.1
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of students: "); int num = input.nextInt(); int score[] = new int[num]; System.out.print("Enter "+ num + " scores: "); for(int i = 0; i < num; i++) { score[i] = input.nextInt(); } int best = score[0]; for(int i = 1; i < num; i++) { if(best < score[i]) { best = score[i]; } } char grade[] = new char[num]; for(int i = 0; i < num; i++) { if(score[i] >= best-10) { grade[i] = 'A'; } else if(score[i] >= best-20) { grade[i] = 'B'; } else if(score[i] >= best-30) { grade[i] = 'C'; } else if(score[i] >= best-40) { grade[i] = 'D'; } else { grade[i] = 'F'; } System.out.println("Student "+i+" score is "+score[i]+" and grade is "+grade[i]); } } }
7.2
import java.util.Scanner; public class Main { public static void main(String[] args) { int numbers[] = new int[10]; System.out.print("Enter ten number: "); Scanner input = new Scanner(System.in); for(int i = 0; i < 10 ;i++) { numbers[i] = input.nextInt(); } System.out.print("Reverse output:"); for(int i = 9; i >= 0; i--) { System.out.print(numbers[i]+" "); } } }