TQC110- import java.io.*;
- import java.util.*;
- public class TQC110
- {
- public static void main(String arg[])
- {
-
- //取得出題數量
- int userItemCoount = arg.length / 2;
-
- //是否為使用者出題(自由出題)
- Boolean isUserItem = (userItemCoount > 0);
-
- //宣告題目陣列
- String itemQue[];
- String itemAns[];
- //判斷是否是自由出題
- if(isUserItem)
- {
- //是自由出題
-
- //建立陣列
- itemQue = new String[userItemCoount];
- itemAns = new String[userItemCoount];
- //寫入題目
- for(int i=0;i<arg.length;i+=2)
- {
- itemQue[i/2] = arg[i];
- itemAns[i/2] = arg[i+1];
- }
- }else{
- //是預設題目
- itemQue = new String[]{"電腦","資料庫","語法","學校","假期"};
- itemAns = new String[]{"computer","database","syntax","school","Vocation"};
- }
- //紀錄開始時間
- long startTime = new Date().getTime();
-
- //顯示資訊
- System.out.println("請將題目的中文字彙翻譯成英文單字!");
- System.out.println("輸入英文單字答案後請按Enter鍵:\n");
-
- //輸入擷取物件
- Scanner scanner =new Scanner(System.in);
-
- //宣告答對題目數變數
- int Right=0;
- //開始出題
- for(int i=0;i<itemQue.length;i++)
- {
- System.out.println("第" + (i+1) +"題__ " + itemQue[i]);
- String useInput = scanner.next();
-
- String ans = itemAns[i].toLowerCase();
- useInput = useInput.toLowerCase();
-
- if(useInput.equals(ans))
- {
- System.out.println("答對了!");
- Right++;
- }else{
- System.out.println("答錯了!");
- System.out.println("正確答案是" + itemAns[i]+"\n");
- }
-
- }
- //結算時間
- long endTime = new Date().getTime();
- long useTime = (endTime-startTime)/1000;
-
- System.out.println("你使用了" + useTime + "秒,在" + itemQue.length + "題中答對了" + Right + "題");
- }
- }
複製代碼 TQC201- import java.util.*;
- public class TQC201
- {
- public static void main(String arg[])
- {
- Scanner s = new Scanner(System.in);
- System.out.print("請輸入 Z 可能的最大值:");
- long z = Integer.parseInt(s.next());
- long tot=0;
- for(long x=1;x<=100000;x++)
- {
- long y = 3 * (x*x) + x*2 +1 ;
- if(y>z)
- {
- System.out.printf("當 x =%d 時, Y =%d , Z =%d,符合 Y < Z 的條件",x-1,tot,z);
- break;
- }
- tot=y ;
- }
- }
- }
複製代碼 TQC202- public class TQC202
- {
- public static void main(String[] args)
- {
- System.out.println("年\tA銀行(複利)\tB銀行(單利)");
- System.out.println("-------------------------------------");
- int p=1000;
- double r=0.05;
- int n=10;
- for(int i=1;i<=n;i++)
- {
- int m1=(int)(p*Math.pow(1+r,i));
- int m2=(int)(p*(1+i*r));
- System.out.printf("%d\t%d\t%d\n",i,m1,m2);
- }
- }
- }
複製代碼 TQC203- import java.util.*;
- public class TQC203 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- if(args.length!=1)
- {
- System.out.println("參數錯誤!字串中不得有空白或必須以逗號隔開");
- return;
- }
- String str[]=args[0].split(",");
- System.out.println("逗號隔開的字串個數共有:"+str.length);
- for(int i=0;i<str.length;i++)
- {
- System.out.println((i+1)+"."+str[i]);
- }
- }
- }
複製代碼 |