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.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
// 判斷BMI | |
public class Q940304 { | |
public static void main(String[] args) throws IOException { | |
String fileName = "940304.SM"; | |
FileReader fr = new FileReader(fileName); | |
BufferedReader br = new BufferedReader(fr); |
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 Q940303 { | |
public static void main(String[] args) throws FileNotFoundException { | |
String fileName = "940303.SM"; | |
File f = new File(fileName); | |
Scanner sc = new Scanner(f); |
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.IOException; | |
import java.util.Scanner; | |
// 數列直角三角形 | |
public class Q940302 { | |
public static void main(String[] args) throws IOException { | |
String fileName = "940302.SM"; | |
File f = new File(fileName); | |
Scanner sc = new Scanner(f); |
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.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
// 回文 | |
public class Q940301 { | |
public static void main(String[] args) throws IOException { | |
String fileName = "940301.SM"; | |
FileReader fr = new FileReader(fileName); |
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
Abstract Class(抽像類別),Interface(介面or接口) | |
Abstract Class(抽像類別): | |
---------------------------------------------------------------------------------------- | |
[1]...顧名思義因為是抽象,所以無法產生(new)物件 | |
abstract class AbClass{ | |
-- aaa() 是有明確定義的方法 | |
void aaa(){ | |
// method here | |
} |
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
class 類別基本理論 | |
class 是個很抽象的東西,可以把它當成是"設計圖"。 | |
用人來比喻,一點一點的建構出來: | |
先不考慮公有(public)與私有(private) | |
我們定義一個人 | |
**(類別) | |
public class People{ | |
} |
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{ |
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
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 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')) |