標題:
JAVA TQC"101~110" 答案大全
[打印本頁]
作者:
p17johnny
時間:
2012-1-28 11:48
標題:
JAVA TQC"101~110" 答案大全
本帖最後由 p17johnny 於 2012-1-28 11:50 編輯
TQC101
public class TQC101
{
public TQC101() {}
public static void main(String[] args)
{
int num[];
num=new int[8];
int i,j;
i=1;
do{
num[i]=(int)(Math.random()*42) + 1;
for( j = 1 ; j < i ; j++ ){
if(num[i] == num[j])
continue;
}
i++;
}while( i<8 );
for ( i = 1; i < 7 ; i++ ){
if( num[i] < 10 )
System.out.println("第"+i+"個號碼:0"+num[i]);
else
System.out.println("第"+i+"個號碼:"+num[i]);
}
if( num[7] < 10 )
System.out.println("特別號:0"+num[i]);
else
System.out.println("特別號:"+num[i]);
}
}
複製代碼
TQC102
import java.util.*;
import java.text.*;
public class TQC102 {
public static void main(String[] args) {
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf1 =
new SimpleDateFormat("yyyy/M/d a hh:mm");
SimpleDateFormat sdf2 =
new SimpleDateFormat("yyyy/M/d a hh:mm:ss");
SimpleDateFormat sdf3 =
new SimpleDateFormat("yyyy年M月d日 a hh時mm分ss秒");
SimpleDateFormat sdf4 =
new SimpleDateFormat("yyyy年M月d日 E a hh時mm分ss秒 z");
System.out.println("--------------------------");
System.out.println(" 當地時間 ");
System.out.println("--------------------------");
System.out.println(sdf1.format(date));
System.out.println(sdf2.format(date));
System.out.println(sdf3.format(date));
System.out.println(sdf4.format(date));
}
}
複製代碼
TQC103
import java.io.*;
import java.util.Arrays; //可以使用Array提供的sort方法
public class TQC103{
public static void main(String args[]){
try{
int[] rdmNum;
int inputNum;
int i;
final int bigNum = 1000;
//建一個BufferReader讀取使用者輸入的數值
BufferedReader bin = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("請輸入欲產生之亂數個數:");
inputNum = Integer.parseInt(bin.readLine());
rdmNum = new int[inputNum];
for( i=0 ; i<inputNum ; i++ ){
rdmNum[i] = (int)(Math.random()*bigNum) ;
}
Arrays.sort(rdmNum);
for( i=0 ; i<inputNum ; i++ ){
System.out.print( rdmNum[i] + "\t" );
}
}catch(Exception e){
}
}
}
複製代碼
TQC104
public class TQC104 {
public static void main(String[] args) {
int a[]={0,1,2,3,4,5,6,7,8,9};
boolean check=false;
int i,j,c1,c2,c3,r1,r2,r3,x1,x2;
do{
for( i=1 ; i<a.length ; i++){
j=(int)(Math.random()*9)+1;
a[0] = a[i];
a[i] = a[j];
a[j] = a[0];
}
c1=a[1]+a[2]+a[3];
c2=a[4]+a[5]+a[6];
c3=a[7]+a[8]+a[9];
r1=a[1]+a[4]+a[7];
r2=a[2]+a[5]+a[8];
r3=a[3]+a[6]+a[9];
x1=a[1]+a[5]+a[9];
x2=a[3]+a[5]+a[7];
if( c1==15 && c2==15 && c3==15 && r1==15 && r2==15 && r3==15
&& x1==15 && x2==15){
check=true;
}
}while(check==false);
System.out.println("答案為:");
System.out.println(a[1] + " " + a[2] + " " + a[3] );
System.out.println(a[4] + " " + a[5] + " " + a[6] );
System.out.println(a[7] + " " + a[8] + " " + a[9] );
System.out.println("不論橫向縱向及對角線加起來的和都是:15");
}
}
複製代碼
TQC105
import java.io.*;
public class TQC105 {
public static void main(String[] args){
try{
int row,col;
int i,j;
String tmp;
int aryA[][];
int aryB[][];
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("請輸入陣列列數:");
row = Integer.parseInt(bin.readLine());
System.out.println("每一列陣列裡要幾個數字:");
col = Integer.parseInt(bin.readLine());
aryA = new int[row][col];
aryB = new int[col][row];
for( i=0 ; i<row ; i++){
System.out.println("請輸入第 "+ i +"列");
tmp = bin.readLine();
String[] strA = tmp.split(" ");
for( j=0 ; j<col ; j++ ){
aryA[i][j]=Integer.parseInt(strA[j]);
}
}
//行列轉換
for( i=0 ; i<row ; i++){
for( j=0 ; j<col ; j++){
aryB[j][i]=aryA[i][j];
}
}
System.out.println("陣列經行列轉換結果");
for( i=0 ; i<col ; i++){
for( j=0 ; j<row ; j++){
System.out.print(aryA[j][i] + " ");
}
System.out.println();
}
}catch(Exception e){
System.out.println("請輸入數字");
e.printStackTrace();
}
}
}
複製代碼
TQC106
public class TQC106
{
//程式進入點
public static void main(String args[])
{
int sum = 0;//自己打? 自己看題目XD
int j = 0; //自己打? 自己看題目XD
int k = 0; //自己打? 自己看題目XD
for(int i=0 ; i<args.length ; i++){
try{
sum += Integer.parseInt(args[i]);
j++;
}
catch(NumberFormatException e){
k++;
}
}
System.out.println("數值之總合為:" + sum );
System.out.println("非數值個數為:" + k );
System.out.println("純數值個數為:" + j );
}
}
複製代碼
TQC107不會寫˙˙
TQC108
import java.lang.*;
public class TQC108
{
public static void main(String[] args)
{
for(int i = 1 ; i< 10 ; i++){
for(int j = 1 ; j <10 ; j++)
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
System.out.println();
}
}
}
複製代碼
TQC109
public class TQC109 {
public static void main(String args[]) {
int r;
r=(int)(Math.random()*100+1);
double area = r*r*Math.PI;
double vol = r*r*r*Math.PI*43;
System.out.println( "隨機產生的半徑為:" + r );
System.out.println( "計算後,直徑為:" + (2*r) );
System.out.println( "計算後,圓面積為:" + area );
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
System.out.println( "計算後,圓體積為:" + vol );
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
}
}
複製代碼
TQC110
import java.io.*;
import java.util.Date;
class TQC110{
String items[][];
long start, end;
Date d;
BufferedReader br;
public static void main(String args[]){
int total = args.length;
int pairs = total / 2;
TQC110 tte;
if(total != 0 && pairs != 0)
{
//get value from args..
String[][] tt = new String[pairs][2];
for(int i=0; i<pairs; i+=2){
tt[i][0] = args[i];
tt[i][1] = args[i+1];
}
tte = new TQC110(tt);
}else
tte = new TQC110();
tte.start();
}
TQC110(){
items = new String[5][2];
items[0][0] = "電腦";
items[0][1] = "computer";
items[1][0] = "資料庫";
items[1][1] = "database";
items[2][0] = "語法";
items[2][1] = "syntax";
items[3][0] = "學校";
items[3][1] = "school";
items[4][0] = "假期";
items[4][1] = "vacation";
//make default value
br = new BufferedReader(new InputStreamReader(System.in));
}
TQC110(String[][] it){
items = it;
br = new BufferedReader(new InputStreamReader(System.in));
}
void start(){
String ans = "";
int correct = 0; // 計算答對題數
d = new Date();
start = d.getTime(); // 開始答題時間
System.out.println("請將題目的中文詞彙翻譯成英文單字!");
System.out.println("輸入英文單字答案後請按Enter鍵:");
System.out.println(" ");
for(int j = 0; j < items.length ; j++)
{
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
try{
ans = br.readLine();
}
catch(IOException ioexception){
System.out.println(ioexception);
}
if(ans.equalsIgnoreCase(items[j][1])){
correct+=1;
System.out.println("答對了!");
//count correct
//ouput correct message
}else{
System.out.println("答錯了! 正確答案是:" + items[j][1]);
//ouput incorrect message
}
}
d = new Date();
end = d.getTime(); // 結束答題時間
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
System.out.println(items.length + "題中答對了" + correct + "題");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2