
文章插圖
大家好,小耶來為大家解答以上的問題 。java 調用dll,java 面向對象編程這個很多人還不知道,現在讓我們一起來看看吧!
1、一共三個類:、和,具體為:public class ScoreArray {private int[] scores;private int scoreCount;public int[] getScores() {return scores;}public int getScoreCount() {return scoreCount;}//構造函數public ScoreArray(int[] scores) {s = scores;for (int score : scores) {if (score >= 0 && score <= 100) {Count++;}}}//求最大值public int getMax() {int[] scores = s;int temp;for (int i = 0; i < h; i++) {for (int j = 0; j < h - 1 - i; j++) {if (scores[j] > scores[j + 1]) {temp = scores[j];scores[j] = scores[j + 1];scores[j + 1] = temp;}}}return scores[h - 1];}//求最小值public int getMin() {int[] scores = s;int temp;for (int i = 0; i < h; i++) {for (int j = 0; j < h - 1 - i; j++) {if (scores[j] > scores[j + 1]) {temp = scores[j];scores[j] = scores[j + 1];scores[j + 1] = temp;}}}return scores[0];}//求均值public double getAvg() {int sum = 0;for (int score : s) {sum += score;}return new BigDecimal(sum).divide(new BigDecimal(h),2, _HALF_UP).doubleValue();}//排序public void sort() {int temp;for (int i = 0; i < h; i++) {for (int j = 0; j < h - 1 - i; j++) {if (s[j] > s[j + 1]) {temp = s[j];s[j] = s[j + 1];s[j + 1] = temp;}}}}//靜態說明類public static void explain() {ln("本類[ScoreArray]實現了數組的:求最值[getMax()]、求均值[getAvg()]和排序[sort()]方法");}}public class StudentScoreArray extends ScoreArray {public StudentScoreArray(int[] scores) {super(scores);}//統計public void statistic() {();Map
2、另外需要遍歷這個map實現統計結果的打?。?我這里使用了java8以后才支持的Lambda表達式,所以你要運行這個程序必須要使用jdk1.8以上的版本 。
3、如果你覺得這樣不妥,可以網上再搜一下map的遍歷方式 。
4、運行結果:啊 代碼又一坨的的擠在一起了,百度知道這個真是無語,我把幾個關鍵的地方截個圖給你康康:成員變量和構造函數忘了說了,構造的同時還統計了有效分數(0~100)的數量求最大值冒泡排序后取最大值求最小值冒泡排序后取最小值求均值利用java 的BigDecimal類解決除法運算精度的問題,四舍五入并保留了兩位小數排序就是冒泡排序,從小到大靜態的文本說明:繼承分數分布統計注意我說的map那里靜態說明文本:測試用例都使用的數組:int[] scores = {59, 60, 82, 58, 71, 99, 0, 59, 65};一共三個類:、和,具體為:public class ScoreArray {private int[] scores;private int scoreCount;public int[] getScores() {return scores;}public int getScoreCount() {return scoreCount;}//構造函數public ScoreArray(int[] scores) {s = scores;for (int score : scores) {if (score >= 0 && score <= 100) {Count++;}}}//求最大值public int getMax() {int[] scores = s;int temp;for (int i = 0; i < h; i++) {for (int j = 0; j < h - 1 - i; j++) {if (scores[j] > scores[j + 1]) {temp = scores[j];scores[j] = scores[j + 1];scores[j + 1] = temp;}}}return scores[h - 1];}//求最小值public int getMin() {int[] scores = s;int temp;for (int i = 0; i < h; i++) {for (int j = 0; j < h - 1 - i; j++) {if (scores[j] > scores[j + 1]) {temp = scores[j];scores[j] = scores[j + 1];scores[j + 1] = temp;}}}return scores[0];}//求均值public double getAvg() {int sum = 0;for (int score : s) {sum += score;}return new BigDecimal(sum).divide(new BigDecimal(h),2, _HALF_UP).doubleValue();}//排序public void sort() {int temp;for (int i = 0; i < h; i++) {for (int j = 0; j < h - 1 - i; j++) {if (s[j] > s[j + 1]) {temp = s[j];s[j] = s[j + 1];s[j + 1] = temp;}}}}//靜態說明類public static void explain() {ln("本類[ScoreArray]實現了數組的:求最值[getMax()]、求均值[getAvg()]和排序[sort()]方法");}}public class StudentScoreArray extends ScoreArray {public StudentScoreArray(int[] scores) {super(scores);}//統計public void statistic() {();Map
5、另外需要遍歷這個map實現統計結果的打印 , 我這里使用了java8以后才支持的Lambda表達式,所以你要運行這個程序必須要使用jdk1.8以上的版本 。
6、如果你覺得這樣不妥,可以網上再搜一下map的遍歷方式 。
7、運行結果:啊 代碼又一坨的的擠在一起了,百度知道這個真是無語,我把幾個關鍵的地方截個圖給你康康:忘了說了 , 構造的同時還統計了有效分數(0~100)的數量冒泡排序后取最大值冒泡排序后取最小值利用java 的BigDecimal類解決除法運算精度的問題,四舍五入并保留了兩位小數就是冒泡排序,從小到大:注意我說的map那里:測試用例都使用的數組:int[] scores = {59, 60, 82, 58, 71, 99, 0, 59, 65}; 。
【java 面向對象編程 java 調用dll】本文到此分享完畢,希望對大家有所幫助 。
- 2021跨年說說暖心話語對象50字 2021跨年說說暖心話語對象
- JAVA有幾種集合類型 java有幾種集合
- 某個對象程序庫vbaen32 olb丟失或損壞 vba是什么
- 怎樣教作文
- 面向對象遙感圖像分類方法
- cdx什么意思網絡用語
- 長春2022年春季中小學教師資格認定對象范圍
- java基礎練習題 java基礎試題
- java進度條 JAVA進度條的實時顯示
- 職工醫保與居民醫保的區別
