我的學習筆記本
2013年2月26日 星期二
Eclipse外掛UML工具
Step1:把解壓縮的AmaterasUML內的jar檔複製
Step2:至eclipse/pulgins/ 把檔案貼到plugins的目錄底下
Step3:此工具使用方法打開eclipse右鍵點及專案New-->Other...
Step4:AmaterasUML-->Class Diagram-->Next-->Finish
Step5:把寫好的java程式選取拉進
UML工具,工具自動會幫您產生關係圖表
Finish
2013年2月2日 星期六
Collection
2013年1月22日 星期二
宣告三個三維陣列,用foreach迴圈印出
宣告三個三維陣列,用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月5日 星期六
Java-驗證身分證的Method
--------------------------------------------------------------------------------------------------------
public class IDCheck {
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;
}
}
}
--------------------------------------------------------------------------------------------------------
2012年12月20日 星期四
Java-StringBuffer比對內容是否對稱
public class Play3{
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("123345");
System.out.println(sb);
System.out.println("長度"+sb.length());
System.out.println("等下要比對次數"+sb.length()/2);
int f=0;
int l=sb.length()-1;
for(int i= 0 ; i<sb.length()/2;i++)
{
if(sb.toString().charAt(f) == sb.toString().charAt(l))
{
System.out.print("第"+(i+1)+"個跟後面數來第"+(i+1)+"個有一樣");
break;
}
f++;
l--;
}
}
}
Java-寫出一個過濾陣列的Method
public int[] deleteSameNumber(int[] ary)
{
int[] a = new int[ary.length];
int k = 0;
for (int i = 0 ; i<ary.length ; i++)
{
int exist = 0;
//此值用來檢查是否有重複性
for(int j = 0; j<a.length;j++)
{
if(ary[i] == a[j]) exist =1;
}
if (exist == 0) a[k++]=ary[i];
//表示傳進去的ary[i]在a陣列裡沒有
}
return a;
}
2012年11月27日 星期二
手動建置一台虛擬的SwitchHub
TUN/TAP 原本就是 Linux 系統所提供的虛擬網路介面裝置,只是預設並不是每套 Linux 的發行版本都有內建此功能。
查看是否有安裝
$tunctl
操控TUN/TAP的套件名稱為"uml_utilities"
$sudo apt-get install uml-utilities
建立一張網路卡名稱為p1只有
student
可以用
$sudo tunctl -t p1 -u user
用BashScript寫一隻程式,可以快速建立網卡
建立橋接裝置br01(這時候建立的只是一個空殼)
$sudo brctl addbr br01
指定一個ip給br01
$sudo ifconfig br01 192.168.10.1/24 up
這時候的bridge抽象是沒有port也就是說沒有洞讓別人聯接進來
底下手洞建立三張網卡br01p1、br0p2、br0p3
$sudo tunctl -t br0p1 -u student
$sudo tunctl -t br0p2 -u student
$sudo tunctl -t br0p3 -u student
$sudo ifconfig br0p1 up
$sudo ifconfig br0p2 up
$sudo ifconfig br0p3 up
然後把網卡加進br01,一台虛擬的SwitchHub就完成了!!!
$sudo brctl addif br01 br0p1
$sudo brctl addif br01 br0p1
$sudo brctl addif br01 br0p1
較新的文章
較舊的文章
首頁
訂閱:
文章 (Atom)