題目要求:印出如下表格:
Microsoft vista九十七年度銷售業績
月份 業績
------ ------------------------------------------
1
2 ********
3 *******
4 *************
5 *********
6 ************
7 **********
8 ********
9 **************
10 *************
11 **************
12 ***************
----------------------------------------------------
銷售金額:??百萬元
-------- code starts ---------
public class ArrayTest2 {
public static void main(String[] args) {
//month ->代表月份
int[] month = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
//data ->代表銷售業績金額
int[] data = {16, 15, 13, 11, 10, 10, 8, 7, 4, 3, 1, 0};
System.out.println("Microsoft vista九十七年度銷售業績");
System.out.println("月份\t業績");
System.out.println("---------------------------------");
//印出月份與業績
for (int i = 0; i < month.length; i++) {
System.out.print(month[i]);
System.out.print("\t");
//以下為列出*的迴圈,印初次數為data[i]
for (int j = 1; j <= data[i]; j++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("----------------------------------");
int sum = 0;
for (int k = 0; k < data.length; k++) {
sum = data[k] + sum;
}
System.out.println("總金額:" + sum + "百萬元");
}
}
沒有留言:
張貼留言