JAVA TQC 201+202+203 答案公布
本帖最後由 p17johnny 於 2012-1-28 17:02 編輯
TQC201- import java.io.*;
- public class JVA201
- {
- TQC201() {}
- public static void main(String args[]) throws Exception
- {
- int x,y,z;
- int x0,y0;
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- System.out.print("請輸入 Z 可能的最大值:");
- z = Integer.parseInt( br.readLine() );
-
- if(z>1){
- x = -1; y=0;
- do{
- x0=x;
- y0=y;
- x++;
- y=(int)(Math.pow(x,2)*3+2*x+1.0);
- }while(y<z);
- System.out.println("當 X = " + x0 +"時, Y = " + y0 + ", Z = " + z +",符合 Y < Z 的條件");
- }else{
- System.out.println("當 X,Y 為正整數時, Y 恆大於等於 1, 故 Z = " + z +",無符合 Y < Z 的最佳解");
- }
- }
- }
複製代碼 TQC202- public class TQC202
- {
- public static void main(String args[])
- {
- double r=0.05;
- int p = 1000;
- int n = 10;
- int m1,m2;
- System.out.println("年 A銀行(複利) B銀行(單利)");
- System.out.println("----------------------------------------");
- for(int i = 1; i <= n ; i++)
- {
- m1 = (int)(p * Math.pow( (1+r) , i ));
- m2 = (int)(p * ( 1 + r*i ));
- System.out.printf("%d\t%d\t\t%d\n",i,m1,m2);
- }
- System.out.println("----------------------------------------");
- }
- }
複製代碼 TQC203- import java.util.*;
- public class TQC203
- {
- public static void main(String[] args)
- {
- if( args.length == 1 ){
-
- String str[]= args[0].split(",");
- int stamt = str.length;
- System.out.println("逗號隔開的字串個數共有: " + stamt);
- for(int i = 0 ; i<stamt ; i++)
- {
- System.out.println( (i+1) + "." + str[i] );
- }
- }
- else{
- System.out.println("參數錯誤!字串不得有空白或必須以逗號隔開");
- }
- }
- }
複製代碼 |