標題:
20120707 上課內容
[打印本頁]
作者:
jerryclass
時間:
2012-7-7 11:39
標題:
20120707 上課內容
上課大綱:TQC 考前練習
8 |7 c9 o L( v5 f/ S0 \( m3 j
練習題目:TQC107、TQC108、TQC204、TQC207
作者:
jerryclass
時間:
2012-7-7 11:39
本帖最後由 jerryclass 於 2012-7-7 11:42 編輯
# h! h6 u5 ^1 q
6 p7 A2 m6 c. y0 Z0 K* x0 |
TQC 107
public class TQC107 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
if (args.length < 2) {
System.out.println("最少需要輸入2個數字");
} else {
double sum = 0;
double count = args.length - 1;
for (int i = 1; i < args.length; i++) {
sum = sum + Integer.valueOf(args[i]);
}
if (args[0].equals("0")) {
System.out.printf("%.0f", sum / count);
} else if (args[0].equals("1")) {
System.out.printf("%.1f", sum / count);
} else if (args[0].equals("2")) {
System.out.printf("%.2f", sum / count);
}
}
}
}
複製代碼
作者:
jerryclass
時間:
2012-7-7 11:56
回復
2#
jerryclass
/ z' i2 L: F: v' V; V
TQC 108
public class TQC108 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
{
System.out.print(String.format("%d*%d=%d\t", i,j,i*j));
}
System.out.println("");
}
}
}
複製代碼
作者:
jerryclass
時間:
2012-7-7 11:57
回復
3#
jerryclass
! D8 M! \$ c8 m" o+ `$ l
9 Q0 D% ?9 B) q
! p# L4 f( p" D9 c; g% Z6 Q% |
TQC204
public class TQC204 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int max = Integer.parseInt(args[0]);
int min = Integer.parseInt(args[0]);
int passCount = 0;
double sum = 0;
for(int i=0;i<args.length;i++)
{
int userIn = Integer.parseInt(args[i]);
if(userIn > max) max = userIn;
if(userIn < min) min = userIn;
if(userIn >= 60) passCount++;
sum = sum + userIn;
}
System.out.printf("本班最高分數是:%d \r\n", max);
System.out.printf("本班最低分數是:%d \r\n", min);
System.out.printf("本班及格人數有%d人60分以上 \r\n", passCount);
System.out.printf("本班期末考總平均是:%.2f分 \r\n", sum/args.length);
}
}
複製代碼
作者:
jerryclass
時間:
2012-7-7 11:58
回復
4#
jerryclass
) b% a+ i) f9 n+ Q# l& M
7 E5 M0 h/ Z4 W) p' @5 y
/ }4 S7 j- _% n* X3 {5 b
TQC 207
public class TQC207 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int max = Integer.parseInt(args[0]);
int oddCount = 0;
int sum = 0;
for(int i=0;i<args.length;i++)
{
int userIn = Integer.parseInt(args[0]);
if(userIn % 2 == 1) oddCount++;
sum = sum + userIn;
}
System.out.printf("最大值= %d \r\n",max);
System.out.printf("奇數的個數= %d \r\n",oddCount);
System.out.printf("數字的總和= %d \r\n",sum);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2