FFF

FB留言板

TQC Java術科解答_類別一



import java.io.*;
public class JVA01
{
public static void main(String args[])
{
int lotto[] = new int[7];
for (int i = 0; i
{
lotto[i] = (int)(Math.random() * 42) + 1;

for (int j = 0; j
{
if (lotto[i] == lotto[j])
{
i--;
}
}
}

for (int x = 0, i = 1; x
{
if (lotto[x] < 10)
{
System.out.println("第\" + i + "個號碼:" + "0" + lotto[x]);
}
else
{
System.out.println("第\" + i + "個號碼:" + lotto[x]);
}
}
System.out.println("特別號:" + lotto[6]);
}
}


//Code From http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/UseDate.htm
import java.text.DateFormat; import java.util.Date;

public class JVA02
{
public static void main(String[] args)
{
Date date = new Date();

DateFormat shortFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.SHORT);

DateFormat mediumFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM);

DateFormat longFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.LONG);

DateFormat fullFormat = DateFormat.getDateTimeInstance(DateFormat.FULL,
DateFormat.FULL); System.out.println("------------------------");
System.out.println("\t當地時間"); System.out.println(
"------------------------"); System.out.println(shortFormat.format(date))
; System.out.println(mediumFormat.format(date)); System.out.println
(longFormat.format(date)); System.out.println(fullFormat.format(date));
}
}


import java.io.*; public class JVA03
{
public static void main(String args[])throws IOException
{
System.out.println("請輸入欲產生之亂數個數:"); BufferedReader br = new
BufferedReader(new InputStreamReader(System.in)); String x = br.readLine()
; int r = Integer.parseInt(x); int random[] = new int[r]; for (int i = 0;
i
{
random[i] = (int)(Math.random() * 999) + 1;
}

int swap = 0; for (int i = 1; i
{
for (int j = 0; j
{
if (random[j] > random[j + 1])
{
swap = random[j]; random[j] = random[j + 1]; random[j + 1] = swap;
}
}
}
for (int i = 0; i
{
System.out.print(random[i] + " ");
}
}
}


//decompiled file...
public class JVA04
{



public static void main(String args[])
{
int ai[] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
}; boolean flag = false; boolean flag1 = true; boolean flag2 = true;
do
{
for (int i = 1; i < ai.length; i++)
{
int j = (int)(Math.random() * 10D); ai[0] = ai[i]; ai[i] = ai[j]; ai[j]
= ai[0];
}

int k = ai[1] + ai[2] + ai[3]; int l = ai[4] + ai[5] + ai[6]; int i1 =
ai[7] + ai[8] + ai[9]; int j1 = ai[1] + ai[4] + ai[7]; int k1 = ai[2] +
ai[5] + ai[8]; int l1 = ai[3] + ai[6] + ai[9]; int i2 = ai[1] + ai[5] +
ai[9]; int j2 = ai[3] + ai[5] + ai[7]; if (k == l && l == i1 && i1 ==
j1 && j1 == k1 && k1 == l1 && l1 == i2 && i2 == j2)flag = true;
}
while (!flag); System.out.println("--CSF範例--"); System.out.println(
"答案為:"); System.out.println(ai[1] + " " + ai[2] + " " + ai[3]);
System.out.println(ai[4] + " " + ai[5] + " " + ai[6]); System.out.println
(ai[7] + " " + ai[8] + " " + ai[9]); System.out.println(
"不論橫向縱向及對角線加起來的和都是 15");
}
}




import java.io.*; import java.util.StringTokenizer;

public class JVA05
{



public static void main(String args[])throws IOException
{
//////////////////////////////////////////////////////////////////////////
try
{
System.out.println("------CSF範例------"); System.out.println(
"請輸入陣列列數\"); BufferedReader br = new BufferedReader(new
InputStreamReader(System.in)); int i = Integer.parseInt(br.readLine());

System.out.println("每一列陣列裡要幾個數字?"); int j = Integer.parseInt
(br.readLine());

String arrayOriginal[][] = new String[i][j];

String arrayConvert[] = new String[j];
//////////////////////////////////////////////////////////////////////////
for (int x = 0; x < i; x++)
{
System.out.println("請輸入第 " + x + " 列");

String s = br.readLine();

StringTokenizer stringtokenizer = new StringTokenizer(s);

for (int y = 0; y < j; y++)
{
arrayConvert[y] = stringtokenizer.nextToken(); arrayOriginal[x][y] =
arrayConvert[y];
}

}
//////////////////////////////////////////////////////////////////////////
System.out.println(" "); System.out.println("陣列經行、列轉換結果:");
String arrayResult[][] = new String[j][i];

for (int x = 0; x < i; x++)
{
for (int y = 0; y < j; y++)arrayResult[y][x] = arrayOriginal[x][y];

}
//////////////////////////////////////////////////////////////////////////
for (int x = 0; x < j; x++)
{
for (int y = 0; y < i; y++)System.out.print(arrayResult[x][y] + " ");

System.out.println();
}

}
catch (Exception exception)
{
System.err.print(exception);
}
}
}



import java.io.*; public class JVA05
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int m = 0; int n = 0;

System.out.println("請輸入陣列列數\"); m = Integer.parseInt(br.readLine());
System.out.println("每一列陣列裡要幾個數字?"); n = Integer.parseInt
(br.readLine());

int convert[][] = new int[m][n]; int value; for (int x = 0; x
{
System.out.println("第\" + x + "次\"); for (int y = 0; y
{
value = Integer.parseInt(br.readLine()); convert[x][y] = value;
}
}

for (int x = 0; x
{
for (int y = 0; y
{
System.out.print(convert[y][x] + " ");
}
System.out.println();
}



}
}

0 comments: