宣告三個三維陣列,用foreach迴圈印出
-------------------------------------------------------------------------------------------------------------------
public class Array {
public Array() {
}
public void showArrays(int[][][]... a) {//這行事實上是用一個四維陣列去接外面的三維陣列
for (int[][][] b : a)
for (int[][] c : b)
for (int[] d : c)
for (int e : d)
System.out.println(e);
}
/** 宣告三個三維陣列,用foreach迴圈印出
* @CHEN-YU-YU(2013/01/23)
*/
public static void main(String[] args) {
int[][][] a = { { { 1, 2, 3 }, { 4, 5, 6 } },
{ { 7, 8, 9 }, { 10, 11, 12 } },
{ { 13, 14, 15 }, { 16, 17, 18 } } };
int[][][] b = { { { 19, 20, 21 }, { 22, 23, 24 } },
{ { 25, 26, 27 }, { 28, 29, 30 } },
{ { 31, 32, 33 }, { 34, 35, 36 } } };
int[][][] c = { { { 37, 38, 39 }, { 40, 41, 42 } },
{ { 43, 44, 45 }, { 46, 47, 48 } },
{ { 49, 50, 51 }, { 52, 53, 54 } } };
Array array = new Array();
array.showArrays(a, b, c);
}
}
------------------------------------------------------------------------------------------------------------------
2013年1月22日 星期二
2013年1月5日 星期六
Java-驗證身分證的Method
--------------------------------------------------------------------------------------------------------
private int convert(char ch){
ch =Character.toUpperCase(ch);
switch(ch){
case 'A': return 10;
case 'B': return 11;
case 'C': return 12;
case 'D': return 13;
case 'E': return 14;
case 'F': return 15;
case 'G': return 16;
case 'H': return 17;
case 'I': return 34;
case 'J': return 18;
case 'K': return 19;
case 'L': return 20;
case 'M': return 21;
case 'N': return 22;
case 'O': return 35;
case 'P': return 23;
case 'Q': return 24;
case 'R': return 25;
case 'S': return 26;
case 'T': return 27;
case 'U': return 28;
case 'V': return 29;
case 'W': return 32;
case 'X': return 30;
case 'Y': return 31;
case 'Z': return 32;
}
return -100;
}
private boolean checkFormat(String id){
if(id.length() !=10){
System.out.println("長度不符合");
return false;
}
for(int i=1; i<10; i++){
char ch = id.charAt(i);
if(!Character.isDigit(ch)){
System.out.println("格式錯誤");
return false;
}
}
return true;
}
public boolean check(String id){
if(!checkFormat(id)){
return false;
}
char ch = id.charAt(0);
int D0 = this.convert(ch);
int D1 = Integer.parseInt(id.substring(1, 2));
int D2 = Integer.parseInt(id.substring(2, 3));
int D3 = Integer.parseInt(id.substring(3, 4));
int D4 = Integer.parseInt(id.substring(4, 5));
int D5 = Integer.parseInt(id.substring(5, 6));
int D6 = Integer.parseInt(id.substring(6, 7));
int D7 = Integer.parseInt(id.substring(7, 8));
int D8 = Integer.parseInt(id.substring(8, 9));
int D9 = Integer.parseInt(id.substring(9, 10));
int X1 = D0/10;
int X2 = D0%10;
int Y = X1+ 9*X2+ 8*D1+ 7*D2+ 6*D3+ 5*D4+4*D5+ 3*D6+ 2*D7+ D8;
int CheckCode = (10-(Y % 10)) % 10;
if(CheckCode==D9) {
return true;
} else {
return false;
}
}
}
--------------------------------------------------------------------------------------------------------
訂閱:
文章 (Atom)