This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package exam; | |
| /* ========== 矩陣相乘 ========== */ | |
| public class Homework1 { | |
| public static void main(String[] args) { | |
| /**------------------------------------------------------------------ | |
| eg.座標對照 | |
| A B | |
| ┌ [0][0] [0][1] ┐ ┌ [0][0] [0][1] [0][2] ┐ | |
| │ [1][0] [1][1] │ X └ [1][0] [1][1] [1][2] ┘ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* ========== 魔術方塊 ========== */ | |
| public class Homework3 { | |
| public static void main(String[] args) { | |
| int size = 5; // 可指定任意奇數 | |
| int[][] array = new int[size][size]; | |
| int count=1; | |
| int i=size-1,j=size/2; // 數字 1 的初始位置 | |
| array[i][j] = count++; // 將 1 放入初始位置 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Random; | |
| /* ========== 英文大小寫、數字隨機組合 ========== */ | |
| public class Random_02 { | |
| public static void main(String[] args) { | |
| /**------------------------------------------------------------------- | |
| Step1 : 建立一個樣本陣列 array[] = {1,2,3,4 ... 65,66,67 ... 97,98,99 ...} | |
| array[] 共 10+26+26 = 62 個 element | |
| Step2 : 從樣本陣列裡取亂數 => array[random(0~62)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.Random; | |
| /* ========== 亂數取不重複 6 個數 ========== */ | |
| public class Random_01 { | |
| public static void main(String[] args) { | |
| Random r = new Random(); | |
| int[] sixNum = new int[6]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.File; | |
| import java.io.FileNotFoundException; | |
| import java.util.Scanner; | |
| public class Ex_9_2 { | |
| public static void main(String[] args) throws FileNotFoundException { | |
| String filepath = "sample.txt"; | |
| File file = new File(filepath); | |
| Scanner scan = new Scanner(file); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CalMain { | |
| public static void main(String[] args) { | |
| CalPlus c1 = new CalPlus(2,4,83,240); | |
| System.out.println(c1.counta+"隻"+c1.countb+"隻"); | |
| CalPlus c2 = new CalPlus(12,15,24,312); | |
| System.out.println("麵包"+c2.counta+"個"+c2.countb+"個"); | |
| } |
NewerOlder