java 面向對象編程 java 調用dll


java 面向對象編程 java 調用dll

文章插圖
大家好,小耶來為大家解答以上的問題 。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 map = new LinkedHashMap<>();for (int i : ores()) {if (insKey(i)) {(i, (i) + 1);} else {(i, 1);}}ch((k, v) -> ln("分數為[" + k + "]的人數為:[" + v + "]"));}//靜態說明類public static void explain() {ln("本類[StudentScoreArray]實現了數組的:求最值[getMax()]、求均值[getAvg()]、排序[sort()]和分布統計[statistic()]方法");}}public class Test1 {public static void main(String[] args) {int[] scores = {59, 60, 82, 58, 71, 99, 0, 59, 65};ScoreArray scoreArray = new ScoreArray(scores);in();("數組內容:[");for (int i : ores()) {(i + " ");}ln("]");ln("有效值個數:" + oreCount());ln("最大值:" + x());ln("最小值:" + n());ln("平均值:" + g());();("排序后數組內容:[");for (int i : ores()) {(i + " ");}ln("]");ln("");ln("========華麗的分割線========");ln("");StudentScoreArray studentScoreArray = new StudentScoreArray(scores);in();("數組內容:[");for (int i : ores()) {(i + ",");}ln("]");ln("有效值個數:" + oreCount());ln("最大值:" + x());ln("最小值:" + n());ln("平均值:" + g());();("排序后數組內容:[");for (int i : ores()) {(i + " ");}ln("]");ln("分數分布統計:");stic();}}其中對StudentScoreArray類我要特別說明一下:統計分布情況時,使用了Map,map是一種key-value的數據結構,其有個特點被我所利用:一個map中只能同時存在一個key , 所以我以分數為key , 以數量為value,遍歷分數數組時,如果是第一次遇到這個key(分數) , 則將其value(數量)置為1;如果已經不是第一次遇見了,則將其value(數量)置為value + 1(數量 + 1) 。
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 map = new LinkedHashMap<>();for (int i : ores()) {if (insKey(i)) {(i, (i) + 1);} else {(i, 1);}}ch((k, v) -> ln("分數為[" + k + "]的人數為:[" + v + "]"));}//靜態說明類public static void explain() {ln("本類[StudentScoreArray]實現了數組的:求最值[getMax()]、求均值[getAvg()]、排序[sort()]和分布統計[statistic()]方法");}}public class Test1 {public static void main(String[] args) {int[] scores = {59, 60, 82, 58, 71, 99, 0, 59, 65};ScoreArray scoreArray = new ScoreArray(scores);in();("數組內容:[");for (int i : ores()) {(i + " ");}ln("]");ln("有效值個數:" + oreCount());ln("最大值:" + x());ln("最小值:" + n());ln("平均值:" + g());();("排序后數組內容:[");for (int i : ores()) {(i + " ");}ln("]");ln("");ln("========華麗的分割線========");ln("");StudentScoreArray studentScoreArray = new StudentScoreArray(scores);in();("數組內容:[");for (int i : ores()) {(i + ",");}ln("]");ln("有效值個數:" + oreCount());ln("最大值:" + x());ln("最小值:" + n());ln("平均值:" + g());();("排序后數組內容:[");for (int i : ores()) {(i + " ");}ln("]");ln("分數分布統計:");stic();}}其中對StudentScoreArray類我要特別說明一下:統計分布情況時,使用了Map,map是一種key-value的數據結構,其有個特點被我所利用:一個map中只能同時存在一個key,所以我以分數為key,以數量為value,遍歷分數數組時,如果是第一次遇到這個key(分數),則將其value(數量)置為1;如果已經不是第一次遇見了,則將其value(數量)置為value + 1(數量 + 1) 。
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】本文到此分享完畢,希望對大家有所幫助 。