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+"個"); | |
} |
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
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.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
/* ========== 魔術方塊 ========== */ | |
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
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 Homework2 { | |
public static void main(String[] args) { | |
String s = "A323456789"; | |
String checkHead = "ABCDEFGHJKLMNPQRSTUVWXYZIO"; // 字母代號對照表 | |
if (s.length()==10){ | |
char[] c = s.toUpperCase().toCharArray(); // 建立 c 陣列,同時將s字串轉大寫後,轉成字元陣列放入 c 陣列 | |
int[] ID = new int [c.length]; // 建立一個運算用的整數陣列,空間為 c 的字元個數 | |
// 驗證首位字母是否合法 (該字元是否能在checkHead[]找到), 驗證第一位是否為 1 or 2 (1=男生, 2=女生) | |
if (checkHead.indexOf(c[0]) == -1 || (c[1] != '1' && c[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
import java.util.Random; | |
/* ========== 身分證產生器 ========== */ | |
public class IDMaker { | |
static String checkHead = "ABCDEFGHJKLMNPQRSTUVWXYZIO"; | |
public static void main(String[] args) { | |
Random r = new Random(); | |
String s = ""; | |
int checknum = 0; // 產生前9碼的同時計算產生驗證碼 | |
// 產生第一個英文字母 |
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 Test03 { | |
public static void main(String[] args) { | |
int length = 13; // 行數可任意變更,配合 work4 建議奇數為主 | |
System.out.println("Work1.."); | |
for (int i = 0; i < length; i++) { | |
for (int j = 0; j < length; j++) | |
System.out.print("★"); | |
System.out.println(); | |
} |
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
polymorphism(多型)、overriding(覆寫)、overloading(多載) | |
// Superclass(父類別) | |
class Animal(){ | |
void sound(){ | |
} | |
} | |
// Subclass(子類別) | |
class Dog extends Animal{ |
OlderNewer