/**
* 語句標籤測試
*
* @author leizhimin 2009-7-16 11:43:08
*/
public class TestLable {
public static void main(String[] args) {
outer:
for (int i = 0; i < 10; i++) {
System.out.println("/nouter_loop:" + i);
inner:
for (int k = 0; i < 10; k++) {
System.out.print(k + " ");
int x = new Random().nextInt(10);
if (x > 7) {
System.out.print(" >>x == " + x + ",結束inner循環,繼續迭代執行outer循環了!");
continue outer;
}
if (x == 1) {
System.out.print(" >>x == 1,跳出並結束整個outer和inner循環!");
break outer;
}
}
}
System.out.println("------>>>所有循環執行完畢!");
}
}
outer_loop:0
0 1 2 3 4 5 6 7 8 9 >>x == 8,結束inner循環,繼續迭代執行outer循環了!
outer_loop:1
0 1 2 3 4 5 >>x == 9,結束inner循環,繼續迭代執行outer循環了!
outer_loop:2
0 1 2 3 4 5 6 7 8 9 >>x == 8,結束inner循環,繼續迭代執行outer循環了!
outer_loop:3
0 1 2 3 4 >>x == 9,結束inner循環,繼續迭代執行outer循環了!
outer_loop:4
0 1 2 3 4 5 6 7 8 9 10 >>x == 8,結束inner循環,繼續迭代執行outer循環了!
outer_loop:5
0 >>x == 1,跳出並結束整個outer和inner循環!------>>>所有循環執行完畢!
Process finished with exit code 0
case intval: 語句代碼;break;
case intval: 語句代碼;break;
case intval: 語句代碼;break;
case intval: 語句代碼;break;
default:
語句代碼;
}
* 漢語金額數字轉換程序
*
* @author leizhimin 2009-7-16 13:28:05
*/
public class TestSwitch {
/**
* 數字轉換爲漢語金額數字
*
* @param num 數字
* @return 漢語金額數字
*/
public static String genCnNum(Long num) {
StringBuffer sb = new StringBuffer();
String snum = String.valueOf(num);
for (char c : snum.toCharArray()) {
sb.append(num2Cn(c));
}
return sb.toString();
}
/**
* 字符數字轉換爲漢語金額數字
*
* @param c 字符數字
* @return 漢語金額數字
*/
private static String num2Cn(char c) {
String res = null;
switch (c) {
case '0':
res = "零";
break;
case '1':
res = "壹";
break;
case '2':
res = "貮";
break;
case '3':
res = "叄";
break;
case '4':
res = "肆";
break;
case '5':
res = "伍";
break;
case '6':
res = "陸";
break;
case '7':
res = "柒";
break;
case '8':
res = "捌";
break;
case '9':
res = "玖";
break;
default:
System.out.println("您的輸入有誤,請重試!");
}
return res;
}
public static void main(String[] args) {
System.out.println(genCnNum(4523586022L));
}
}
Process finished with exit code 0