close

fdgdf sdfsdf dfg fdggg sdfsdf 

銷售產品範例計算
銷售員  產品A(12元) 產品B(16元) 產品C(10元) 產品D(14元) 產品E(17元)
1~ 32~34~54~45~ 33
2~ 64~54~70~65~23
3~ 43~40~45~68 ~60我先用Excel 計算一次,並將二維陣列擴張成a[4][6],每列(i)的一個第一個位置,存放該列的計算總和,每一欄(j)的第一個位置,計算該欄的總和



 166820481690249219722659384544540630561363376886470091039135785166404509521020
public class JavaHomeWork { public static void main(String args[]) { int a[][] = { { 0, 0, 0, 0, 0 ,0}, { 0, 32, 34, 54, 45, 33 }, { 0, 64, 54, 70, 65, 23 }, { 0, 43, 40, 45, 68, 60 } }; int salesMax = 0, sales = 0, ProductsMax = 0; //最高的銷售員,產品總金額  String products = "", MaxProducts = ""; //產品名稱,最高產品名稱  for (int i = 1; i < 4; i++) { System.out.print("第"+i+"位銷售員:"); for (int j = 1; j < 6; j++) {
switch (j) { case 1 : //產品A a[i][j] = a[i][j] * 12; System.out.print("A金額="+a[i][j]+"\t"); products = "A"; break; case 2 : //產品B a[i][j] = a[i][j] * 16; System.out.print("B金額="+a[i][j]+"\t"); products = "B"; break; case 3 : //產品C a[i][j] = a[i][j] * 10; System.out.print("C金額="+a[i][j]+"\t"); products = "C"; break; case 4 : //產品D a[i][j] = a[i][j] * 14; System.out.print("D金額="+a[i][j]+"\t"); products = "D"; break; case 5 : //產品E a[i][j] = a[i][j] * 17; System.out.print("E金額="+a[i][j]+"\t"); products = "E"; break; } a[0][j] = a[0][j] + a[i][j]; if (ProductsMax < a[0][j]) { ProductsMax = a[0][j]; MaxProducts = products; } a[i][0] = a[i][0] + a[i][j]; } if (salesMax < a[i][0]) { salesMax = a[i][0]; sales = i; } System.out.println("\n第" + (i) + "位銷售員的總金額:" + a[i][0]); } System.out.println("第"+sales+"位銷售員總金額最高為:"+salesMax); System.out.println(MaxProducts+"產品銷售總金額最高為:"+ProductsMax); }}
執行結果:第1位銷售員:A金額=384 B金額=544 C金額=540 D金額=630 E金額=561 第1位銷售員的總金額:2659第2位銷售員:A金額=768 B金額=864 C金額=700 D金額=910 E金額=391 第2位銷售員的總金額:3633第3位銷售員:A金額=516 B金額=640 C金額=450 D金額=952 E金額=1020 第3位銷售員的總金額:3578第2位銷售員總金額最高為:3633D產品銷售總金額最高為:2492



.msgcontent .wsharing ul li { text-indent: 0; }



分享

Facebook
Plurk
YAHOO!



 

好站連結:http://tw.myblog.yahoo.com/humphrey93452700

























arrow
arrow
    全站熱搜

    hglfseaupj 發表在 痞客邦 留言(0) 人氣()