結果:
請輸入學生人數:
5
請輸入5個成績:
5674894189
student0 score is 56 grade is D
student1 score is 74 grade is B
student2 score is 89 grade is A
student3 score is 41 grade is D
student4 score is 89 grade is AProcess finished withexit code 0
代碼
packagelesson.l7_array;importjava.util.Scanner;/*** * @Description* @author DQ Email:3056166240@qq.com* @version 1.0* @date* @function* 從鍵盤讀入學生成績,找出最高分,* 并輸出學生成績等級。* ?成績>=最高分-10 等級為’A’* ?成績>=最高分-20 等級為’B’* ?成績>=最高分-30 等級為’C’* ?其余 等級為’D’* 提示:先讀入學生人數,根據人數創建int數組,* 存放學生成績*/publicclassArrayTest1{publicstaticvoidmain(String[] args){Scanner scan=newScanner(System.in);System.out.println("請輸入學生人數:");int n=scan.nextInt();int[]students=newint[n];System.out.println("請輸入5個成績:");int max=0;char[]scores=newchar[n];// 存放學生成績并計算最大值for(int i =0; i < n; i++){students[i]= scan.nextInt();max=Math.max(max, students[i]);}// 判斷學生成績等級并輸出for(int i =0; i < n; i++){if(students[i]>=max-10){scores[i]='A';}elseif(students[i]>=max-20){scores[i]='B';}elseif(students[i]>=max-30){scores[i]='C';}else{scores[i]='D';}System.out.println("student"+i+" score is "+students[i]+" grade is "+scores[i]);}scan.close();}}
注意
二分查找要求原數組為有序序列,從小到大
遞歸解法 public class problem9 {public static void main(String[] args) {int[] arr {1,2,3,4,6,7};int left 0;int right arr.length - 1;int value 2;System.out.println(Arrays.toString(arr));int index …
題目
移動盤子,每一次只能移動一個,小盤子在大盤子上。
打印1 from A to B過程 注意
1)盤子編號的變化和輔助柱子的變化
2)當盤子編號為1時,結束遞歸,此時移動結束
代碼
package p2;/*** Illustratio…
第一次在堆棧中發布 – 總是發現以前的問題足以解決我的問題!我遇到的主要問題是邏輯……即使是偽代碼答案也會很棒.
我正在使用python從文本文件的每一行讀取數據,格式如下:
This is a tweet captured from the twitter api #hashtag http://url.com/si…
題目 代碼1
public class YangHuiTriangle {public static void main(String[] args) {print(10);}public static void print(int num) {int[][] arr new int[num][];for (int i 0; i < num; i) {
// 第一行有 1 個元素, 第 n 行有 n 個元素arr[i] new int[i…