首先點選要複製的資料庫滑鼠右鍵後選工作→產生指令碼
接著會出現摘要的畫面,不想看說明就不要理他直接按下一步再來是選擇要匯出資料庫的內容,如果想全部複製就用預設值,因為我不想複製預存程序我使用了自訂內容
再來這個畫面請按進階做一些進階設定

Dnight 發表在 痞客邦 留言(0) 人氣()

Static block是Java中的一個用來初始化Static屬性的功能
一個Class中的Static block只會執行一次
建構子(constructor)則是每次new一個物件的時候就會執行一次
建構子的名稱要與class名稱相同,並且不允許同樣參數的建構子
使用static block與constructor的方法範例如下

Dnight 發表在 痞客邦 留言(0) 人氣()

生日悖論是考慮下面這個問題:假設一個班級有23個或23個以上的人,那麼至少有兩個人生日相同的機率大於50%,對於60或更多的人,至少有兩個人生日相同的機率大於99%,從引起邏輯角度來看生日悖論不是一種悖論,這邊的悖論是指這個數學事實與一般直覺相抵觸。
將問題重新整理一邊,假設一個班級有N個人,每個人生日的日期是隨機的(不考慮2/29),那麼至少有兩個人生日相同的機率是多少呢?
大約要多少人,至少有兩個人生日相同的機率才會大於50%呢?
看到這個問題一般的直覺會覺得說一年有365天,大概要50~100人以上才會讓至少有兩個人生日相同的機率大於50%吧,怎麼會只要23人呢,事實上解決這個問題可以用簡單的高中數學來想。
考慮此事件的補集:所有人生日都不同的機率

Dnight 發表在 痞客邦 留言(0) 人氣()

使用定時或固定時間間隔有幾個方法一個是Thread.sleep();
方法內填延遲的毫秒數就可以讓程式延遲後再執行
另一種就是使用Timer class這個class的schedule方法有兩個變數以及三個變數詳細的使用方法請見範例範例有兩個class,將要執行的程式碼寫在繼承TimerTask的class裡面然後使用Timer裡面你要用的方法就可以使用定時執行程式的功能了
import java.text.SimpleDateFormat;

Dnight 發表在 痞客邦 留言(0) 人氣()

函數是另一種常見的關係,我們常聽到的函數有二元一次函數跟一元一次函數和三角函數等等
給定兩個nonempty set X,Y,這種relation會有一個特定的對應關係,如同機器一樣經過某種運作方式將X的值轉換成Y,怎麼樣算是一個好的運作方式呢?首先,當然要每一個要方入機器的元素都成產生東西出來,所以對x ∈ X,皆存在y ∈ Y使得(x.y)∈ f,另外我們也希望相同的原料用同一個機器能夠產出固定的產品,所以對所有x ∈ X只會有維一的y ∈ Y使得(x.y)∈f,因此function的定義如下
Definition:
設X,Y為nonempty set 且 f ⊆ X ×Y, 為一個from X to Y的relation.若f滿足下列性質,則稱f為一個from X to Y的函數(function)
(1)對所有x ∈ X, 皆存在 y ∈ Y使得 (x, y) ∈ f .

Dnight 發表在 痞客邦 留言(0) 人氣()


Static這個關鍵字有些人理解是維一的意思,其實他指的是這個屬性是放在類別(class)那一層,不隨著物件(object)的變更去改動的,非static的屬性,每一個物件會有一個值
所以物件A的值改變了,物件B的值並不會改變,但是static的屬性你不管使用物件A、物件B去更動他的值,他的值就是固定在類別上,所以會一起更動,所以他有另一個特性:可以用類別名稱去呼叫,最簡單的例子就像是Math.pow()這種方法(method)一樣,他是static的,如果這個方法還是自己類別的static方法,甚至可以省略類別名稱直接打上方法,以下是程式範例
public class StaticDemo {
public static void main(String[] args) {
StaticDemo obj1 = new StaticDemo();
StaticDemo obj2 = new StaticDemo();
System.out.println("method1:");
System.out.println(obj1.method1());//1
System.out.println(obj2.method1());//1
System.out.println(obj1.method1());//2
System.out.println(obj2.method1());//2
System.out.println("method2:");
System.out.println(StaticDemo.method2());//1
System.out.println(method2());//2
System.out.println(obj1.method2());//3
System.out.println(obj2.method2());//4
}
private int i1=0;
public int method1(){
i1++;
return i1;
}
private static int i2=0;
//private int i2=0;  //this will compile error
public static int method2(){
i2++;
return i2;
}
}

Dnight 發表在 痞客邦 留言(0) 人氣()

關於驗證身份證字號的方法請參考 身份證字號驗證
這個產生器的原理是隨機產生身份證字號,最後用身份證字號公式計算出最後一碼的數字為多少,再將整個字串拼起來
public class ID {
public static void main(String[] args) {
String idNumber = ID.IDRandom();
System.out.println("-------IDGeneratorTest-------");
System.out.println(idNumber);
System.out.println("-------IDGeneratorTest-------");
}
public String str="";
public static String IDRandom(){
char[] idByChar = new char[9];
String iDString = "";
//隨機生成A~Z
int x = (int)Math.floor(Math.random()*26+65);
idByChar[0] = (char) x;
//隨機生成1~2
idByChar[1] = (char)(int)Math.floor(Math.random()*2+49);
//隨機產出第3~第9個數字
for (int i=2;i<9;i++){
idByChar[i] = (char)(int)Math.floor(Math.random()*10+48);
}
//第十個數字由前九個字組成
iDString = new String(idByChar);
ID id = new ID(iDString);
int[] temp = new int[10];
temp[0]= id.D0();
for(int i=1;i<9;i++){
temp[i]=id.DNumber(i);
}
//最後將字組起來送出
temp[9]=(10-(id.CheckCode(temp)%10))%10;
iDString = iDString+temp[9];
return iDString;
}
//D0是找第一個字的代碼,因為有些數字不規律所以要用很多if做判斷
private int D0(){
int D00=0;
int temp = this.str.codePointAt(0);
if(72>=temp && temp>=65)
{
D00 = temp-55;
}else if(78>=temp&&temp>=74){
D00 = temp-56;
}else if(86>=temp&&temp>=80){
D00 = temp-57;
}else if(90>=temp&&temp>=88)
{
D00 =temp-58;
}
switch(temp){
case 74 :
D00 =temp-39;
case 79 :
D00 =temp-44;
break;
case 87 :
D00 =temp-55;
break;
default:
break;
}
//這邊是用來檢查使用者輸入小寫時的判斷式
if(104>=temp && temp>=97)
{
D00 = temp-87;
}else if(110>=temp&&temp>=106){
D00 = temp-88;
}else if(118>=temp&&temp>=112){
D00 = temp-89;
}else if(122>=temp&&temp>=120)
{
D00 =temp-90;
}
switch(temp){
case 106 :
D00 =temp-71;
case 111 :
D00 =temp-76;
break;
case 119 :
D00 =temp-87;
break;
default:
break;
}
return D00;
}
//DNumber用來撿查第2~第10個字,所以判斷式簡單許多
private int DNumber(int i){
int D1=100;
//這個初始100只是用來表示如果他不是0~9這個值就顯示100
//也可以用其他數值來表示,但是要避免使用0~9
int temp = this.str.codePointAt(i);
if(57>=temp&&temp>=48){
D1=temp-48;
}
return D1;
}
//這邊只是輔助計算身份證是否正確
private int CheckCode(int[] X){
int x1=Math.floorDiv(X[0],10);
int x2=X[0]%10;
int Y=x1+(9*x2)+(8*X[1]);
for(int i=2;i<=8;i++)
{
Y=(9-i)*X[i]+Y;
}
return Y;
}
public void ChangeID(String s){
this.str=s;
}
public ID(String s){
this.str=s;
}
public ID(){
}
}

Dnight 發表在 痞客邦 留言(0) 人氣()

關於身份證的規則請查照中華民國國民身份證wiki
codePointAt(i)這個方法是用來取出字串第i位置的字的編碼(左邊數來第一個字位置為0)ASCII table請參照此ASCII wiki
如果要找的是產生器請看此:身份證字號產生器

Dnight 發表在 痞客邦 留言(0) 人氣()

在Java中,如果要將數字轉換成字元或字串,或是反過來將字元字串轉成數字的時候,要充份了解互相轉換的機制,比如說
(char)49會將49以編碼的方式轉換,於是顯示出來的數字是1
如果想要將數字轉換成對應的字元,我通常會先轉換成字串再轉成字元
或許有更好的方法,以下列出各種字元/字串對應成整數的方法
public class demo {
public static void main(String[] args) {
int i = 1;
System.out.println("int to String");//整數轉換成字串
System.out.println(Integer.toString(i));//1 String
System.out.println(""+i);//1 String
System.out.println("int to char");
System.out.println("");
int i2 = 49;
                //整數強制型別轉換成字元會當成編碼解讀
System.out.println((char)i2);//1 char
                //轉換成字串在拆成字元
System.out.println((""+i2).charAt(0));//4 char
System.out.println((""+i2).charAt(1));//9 char
System.out.println("");
char ch = '1';
System.out.println("char to int");
                //強制型別轉換會將字元轉換成編碼數字
System.out.println((int)ch);//49 int
                //Character.getNumbericValue()才能取到原來數字
System.out.println(Character.getNumericValue(ch));//1 int
System.out.println("");
String str ="1";
System.out.println("String to int");
                //Inter.parseInt()可將字串轉為數字
System.out.println(Integer.parseInt(str));//1 int
                //需要讀取字串的編碼數字需要用codePointAt()
System.out.println(str.codePointAt(0));//49 int, ascii of 1
System.out.println("");
}
}

Dnight 發表在 痞客邦 留言(0) 人氣()

昨天聽到朋友說表單有個disable的功能
javascript可以使用.disabled=false和.disabled=true來開關按紐或是輸入表格的地方
於是我試著實作出驗證的表單
結果網頁在此
範例輸入
姓名:張三
密碼:a123@A
日期:2015/07/05

Dnight 發表在 痞客邦 留言(0) 人氣()

Relation中還有一種特別的關係,叫做Order relation,所謂的排序關係符合一些特別的性質,以下是介紹。
假設 X 為 nonempty set 且≼ 為 X 上的 relation. 若X符合以下三種性質,我們稱≼為X上的partial order
1.對所有的x ∈ X,皆有 x ≼ x
2.若x,y ∈ X,x≼y且y≼ x,則 x=y
3.若x,y,z ∈ X ,x≼y且y≼z,則 x≼z

Dnight 發表在 痞客邦 留言(0) 人氣()

在Java裡面時間轉換格式是一個很麻煩的課題
因為時間的表達方法各種各樣,有些人寫2015/07/03,有些人寫07/03/2015,有些人寫July 03 /2015,麻煩的是07/03到底表示的是三月七號還是七月三號呢?
所以在Java裡面有個class來格式化日期的類別叫SimpleDateFormat
關於格式的設定詳情請看api文件Date and Time Patterns
格式設定的語法大概如下

Dnight 發表在 痞客邦 留言(0) 人氣()

« 1 2 3 4 5
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。