Skip to content

[Fix]Example的程式碼出現亂碼 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/CH10/AssertionDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public static void main(String[] args) {
}
else {
assert args.length == 0;
System.out.println("�S����J�޼�");
System.out.println("沒有輸入引數");
}
}
}
6 changes: 3 additions & 3 deletions example/CH10/CatchWho.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ public static void main(String[] args) {
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(
"ArrayIndexOutOfBoundsException" +
"/���htry-catch");
"/內層try-catch");
}

throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("�o��ArithmeticException");
System.out.println("發生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(
"ArrayIndexOutOfBoundsException" +
"/�~�htry-catch");
"/外層try-catch");
}
}
}
6 changes: 3 additions & 3 deletions example/CH10/CatchWho2.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ public static void main(String[] args) {
catch(ArithmeticException e) {
System.out.println(
"ArrayIndexOutOfBoundsException" +
"/¤º¼htry-catch");
"/內層try-catch");
}

throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("µo¥ÍArithmeticException");
System.out.println("發生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(
"ArrayIndexOutOfBoundsException" +
"/¥~¼htry-catch");
"/外層try-catch");
}
}
}
4 changes: 2 additions & 2 deletions example/CH10/CheckArgsDemo.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
public class CheckArgsDemo {
public static void main(String[] args) {
try {
System.out.printf("���� %s �\��%n", args[0]);
System.out.printf("執行 %s 功能%n", args[0]);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println("�S�����w�޼�");
System.out.println("沒有指定引數");
e.printStackTrace();
}
}
Expand Down
6 changes: 3 additions & 3 deletions example/CH10/CheckedExceptionDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ public static void main(String[] args) {
try {
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
System.out.print("�п�J���: ");
System.out.print("請輸入整數: ");
int input = Integer.parseInt(buf.readLine());
System.out.println("input x 10 = " + (input*10));
}
catch(IOException e) {
System.out.println("I/O���~");
System.out.println("I/O錯誤");
}
catch(NumberFormatException e) {
System.out.println("��J���������");
System.out.println("輸入必須為整數");
}
}
}
2 changes: 1 addition & 1 deletion example/CH10/ExceptionDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class ExceptionDemo {
public static void main(String[] args) {
try {
throw new ArithmeticException("¨Ò¥~´ú¸Õ");
throw new ArithmeticException("例外測試");
}
catch(Exception e) {
System.out.println(e.toString());
Expand Down
2 changes: 1 addition & 1 deletion example/CH10/ExceptionDemo2.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class ExceptionDemo2 {
public static void main(String[] args) {
try {
throw new ArithmeticException("¨Ò¥~´ú¸Õ");
throw new ArithmeticException("例外測試");
}
catch(ArithmeticException e) {
System.out.println(e.toString());
Expand Down
4 changes: 2 additions & 2 deletions example/CH10/ThrowDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ public class ThrowDemo {
public static void main(String[] args) {
try {
double data = 100 / 0.0;
System.out.println("�B�I�ư��H�s�G" + data);
System.out.println("浮點數除以零:" + data);
if(String.valueOf(data).equals("Infinity"))
throw new ArithmeticException("���s�ҥ~");
throw new ArithmeticException("除零例外");
}
catch(ArithmeticException e) {
System.out.println(e);
Expand Down
6 changes: 3 additions & 3 deletions example/CH10/ThrowsDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ public static void main(String[] args) {
throwsTest();
}
catch(ArithmeticException e) {
System.out.println("�����ҥ~");
System.out.println("捕捉例外");
}
}

private static void throwsTest()
throws ArithmeticException {
System.out.println("�o�u�O�@�Ӵ���");
// �{���B�z�L�{���]�o�ͨҥ~
System.out.println("這只是一個測試");
// 程式處理過程假設發生例外
throw new ArithmeticException();
}
}
6 changes: 3 additions & 3 deletions example/CH11/DetailAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ public enum DetailAction {
public String getDescription() {
switch(this.ordinal()) {
case 0:
return "�V����";
return "向左轉";
case 1:
return "�V�k��";
return "向右轉";
case 2:
return "�g��";
return "射擊";
default:
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions example/CH11/DetailAction2.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
public enum DetailAction2 {
TURN_LEFT("�V����"), TURN_RIGHT("�V�k��"), SHOOT("�g��");
TURN_LEFT("向左轉"), TURN_RIGHT("向右轉"), SHOOT("射擊");

private String description;

// �����}���غc��k
// 不公開的建構方法
private DetailAction2(String description) {
this.description = description;
}
Expand Down
4 changes: 2 additions & 2 deletions example/CH11/DetailAction3.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
public enum DetailAction3 implements IDescription {
TURN_LEFT("�V����"), TURN_RIGHT("�V�k��"), SHOOT("�g��");
TURN_LEFT("向左轉"), TURN_RIGHT("向右轉"), SHOOT("射擊");

private String description;

// �����}���غc��k
// 不公開的建構方法
private DetailAction3(String description) {
this.description = description;
}
Expand Down
2 changes: 1 addition & 1 deletion example/CH11/DetailActionDemo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public class DetailActionDemo {
public static void main(String[] args) {
for(DetailAction action : DetailAction.values()) {
System.out.printf("%s¡G%s%n",
System.out.printf("%s%s%n",
action, action.getDescription());
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/CH11/EnumCompareTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static void main(String[] args) {
}

public static void compareToAction(Action inputAction) {
System.out.println("��J�G" + inputAction);
System.out.println("輸入:" + inputAction);
for(Action action: Action.values()) {
System.out.println(action.compareTo(inputAction));
}
Expand Down
6 changes: 3 additions & 3 deletions example/CH11/EnumDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public static void main(String[] args) {
public static void doAction(Action action) {
switch(action) {
case TURN_LEFT:
System.out.println("�V����");
System.out.println("向左轉");
break;
case TURN_RIGHT:
System.out.println("�V�k��");
System.out.println("向右轉");
break;
case SHOOT:
System.out.println("�g��");
System.out.println("射擊");
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions example/CH11/EnumDemo2.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public static void main(String[] args) {
public static void doAction(InnerAction action) {
switch(action) {
case TURN_LEFT:
System.out.println("�V����");
System.out.println("向左轉");
break;
case TURN_RIGHT:
System.out.println("�V�k��");
System.out.println("向右轉");
break;
case SHOOT:
System.out.println("�g��");
System.out.println("射擊");
break;
}
}
Expand Down
18 changes: 9 additions & 9 deletions example/CH11/MoreAction.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
public enum MoreAction implements IDescription {
TURN_LEFT {
// ��@�����W����k
// 實作介面上的方法
public String getDescription() {
return "�V����";
return "向左轉";
}
}, // �O�o�o�䪺�C�|�Ȥ��j�ϥ� ,
}, // 記得這邊的列舉值分隔使用 ,

TURN_RIGHT {
// ��@�����W����k
// 實作介面上的方法
public String getDescription() {
return "�V�k��";
return "向右轉";
}
}, // �O�o�o�䪺�C�|�Ȥ��j�ϥ� ,
}, // 記得這邊的列舉值分隔使用 ,

SHOOT {
// ��@�����W����k
// 實作介面上的方法
public String getDescription() {
return "�g��";
return "射擊";
}
}; // �O�o�o�䪺�C�|�ȵ����ϥ� ;
}; // 記得這邊的列舉值結束使用 ;
}
20 changes: 10 additions & 10 deletions example/CH11/MoreAction2.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
public enum MoreAction2 {
TURN_LEFT {
// ��@��H��k
// 實作抽象方法
public String getDescription() {
return "�V����";
return "向左轉";
}
}, // �O�o�o�䪺�C�|�Ȥ��j�ϥ� ,
}, // 記得這邊的列舉值分隔使用 ,

TURN_RIGHT {
// ��@��H��k
// 實作抽象方法
public String getDescription() {
return "�V�k��";
return "向右轉";
}
}, // �O�o�o�䪺�C�|�Ȥ��j�ϥ� ,
}, // 記得這邊的列舉值分隔使用 ,

SHOOT {
// ��@��H��k
// 實作抽象方法
public String getDescription() {
return "�g��";
return "射擊";
}
}; // �O�o�o�䪺�C�|�ȵ����ϥ� ;
}; // 記得這邊的列舉值結束使用 ;

// �ŧi�ө�H��k
// 宣告個抽象方法
public abstract String getDescription();
}
2 changes: 1 addition & 1 deletion example/CH11/MoreActionDemo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public class MoreActionDemo {
public static void main(String[] args) {
for(MoreAction action : MoreAction.values()) {
System.out.printf("%s¡G%s%n",
System.out.printf("%s%s%n",
action, action.getDescription());
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/CH13/ArrayListDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static void main(String[] args) {

List<String> list = new ArrayList<String>();

System.out.println("��J�W��(�ϥ�quit����)");
System.out.println("輸入名稱(使用quit結束)");

while(true) {
System.out.print("# ");
Expand All @@ -19,7 +19,7 @@ public static void main(String[] args) {
list.add(input);
}

System.out.print("��ܿ�J: ");
System.out.print("顯示輸入: ");
for(int i = 0; i < list.size(); i++)
System.out.print(list.get(i) + " ");
System.out.println();
Expand Down
4 changes: 2 additions & 2 deletions example/CH13/EnhancedForDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static void main(String[] args) {

List<String> list = new ArrayList<String>();

System.out.println("輸入名稱(輸入quit結束)");
System.out.println("輸入名稱(輸入quit結束)");
while(true) {
System.out.print("# ");
String input = scanner.next();
Expand All @@ -18,7 +18,7 @@ public static void main(String[] args) {
list.add(input);
}

// 使用foreach來遍訪List中的元素
// 使用foreach來遍訪List中的元素
for(String s : list) {
System.out.print(s + " ");
}
Expand Down
6 changes: 3 additions & 3 deletions example/CH13/EnumMapDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public static void main(String[] args) {
Map<Action, String> map =
new EnumMap<Action, String>(Action.class);

map.put(Action.TURN_LEFT, "�V����");
map.put(Action.TURN_RIGHT, "�V�k��");
map.put(Action.SHOOT, "�g��");
map.put(Action.TURN_LEFT, "向左轉");
map.put(Action.TURN_RIGHT, "向右轉");
map.put(Action.SHOOT, "射擊");

for(Action action : Action.values( ) ) {
System.out.println(map.get(action));
Expand Down
6 changes: 3 additions & 3 deletions example/CH13/EnumMapDemo2.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public static void main(String[] args) {
Map<Action, String> map =
new EnumMap<Action, String>(Action.class);

map.put(Action.SHOOT, "�g��");
map.put(Action.TURN_RIGHT, "�V�k��");
map.put(Action.TURN_LEFT, "�V����");
map.put(Action.SHOOT, "射擊");
map.put(Action.TURN_RIGHT, "向右轉");
map.put(Action.TURN_LEFT, "向左轉");

for(String value : map.values( )) {
System.out.println(value);
Expand Down
8 changes: 4 additions & 4 deletions example/CH13/EnumSetDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import java.util.*;

// �w�q�C�|���A
// 定義列舉型態
enum FontConstant { Plain, Bold, Italic }

public class EnumSetDemo {
public static void main(String[] args) {
// �إߦC�|�ȶ��X
// 建立列舉值集合
EnumSet<FontConstant> enumSet =
EnumSet.of(FontConstant.Plain,
FontConstant.Bold);
// ��ܶ��X���e
// 顯示集合內容
showEnumSet(enumSet);
// ��ܸɶ��X���e
// 顯示補集合內容
showEnumSet(EnumSet.complementOf(enumSet));
}

Expand Down
Loading