標籤

二元樹 (1) 字串常數池 (1) 投資 (3) 每月損益 (37) 例外處理 (1) 泛型 (2) 股票 (15) 指標 (5) 英文 (8) 基本資料型別 (1) 期貨 (1) 程式交易 (10) 量化投資 (5) 亂亂寫 (3) 概念 (3) 資料結構 (3) 演算法 (3) 數學 (3) 轉型 (1) AMA (1) ArrayList (1) assert (1) BeautifulSoup (1) C/C++ (8) casting (1) ClassCastException (1) classpath (1) Collection (4) Comparable (1) comparTo() (1) constructor (1) database (3) Debian (1) Dropbox (2) EA (2) enum (1) equals() (2) exception (3) extends (1) ffmpeg (1) final (1) Git (1) HashMap (1) HashSet (1) hasNext() (1) HTS (3) instanceof (1) IS-A (1) Iterator (1) JAVA (43) length (1) Linux (31) List (1) Mac (6) Map (1) ML (2) MT4 (6) MySQL (2) next() (1) NullPointerException (1) Number (1) Numpy (2) OpenCart (1) OpenCV (3) OSX (1) overloading (1) overriding (3) pandas (2) PHP (8) PriorityQueue (1) Python (11) Queue (1) random() (1) reverse() (1) Samba (1) SCJP (21) sqrt() (1) synchronized (1) talib (1) ufw (1) uTorrent (1) var-args (2) VHF (1) vim (2) Yhoo知識+ (4)

2012年12月8日 星期六

linux重灌後無法ssh

linux重灌後發現ssh產生錯誤:


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
76:bd:e0:e9:c2:13:6d:ca:d8:eb:b2:a8:58:9b:4b:b6.
Please contact your system administrator.
Add correct host key in /Users/superppp/.ssh/known_hosts to get rid of this message.
Offending key in /Users/superppp/.ssh/known_hosts:1
RSA host key for 192.168.1.101 has changed and you have requested strict checking.
Host key verification failed.

解決方式:

$ ssh-keygen -R 192.168.1.101
/Users/superppp/.ssh/known_hosts updated.
Original contents retained as /Users/superppp/.ssh/known_hosts.old

參考自這裡


linux新增使用者帳密

#useradd Name 
#passwd Name

2012年12月7日 星期五

三維陣列走訪

試撰寫一程式,請利用三維列陣A完成下列題目的要求。列陣A的值如下
int A[][][]={{{15,50,65},{38,94,25},
{79,44,19},{89,54,73}},
    {{14,90,46},{43,23,67},
{32,56,78},{94,78,40}}};

(a)請印出陣列內容。
(b)在陣列A裡找出所有大於等於50的元素,將該元素重新設值為99。
(c)印出完成(b)之後的陣列內容。


--------------------------------------

public class Array99{
public static void main(String[] args){
int[][][] A={{{15,50,65},{38,94,25},{79,44,19},{89,54,73}},
    {{14,90,46},{43,23,67},{32,56,78},{94,78,40}}};
    showArray(A);
    showArray(A);
}
public static void showArray(int[][][] a){
for(int i=0; i<a.length; i++){
for(int j=0; j<a[0].length; j++){
for(int k=0; k<a[0][0].length; k++){
System.out.print(a[i][j][k]+ " ");
if(a[i][j][k]>=50) a[i][j][k] = 99;
}
System.out.println();
}
}
System.out.println();
}
}

補充:其實for迴圈那裡用for-each會比較好理解,如for(int[][] b: a)...for(int[] c: b)...for(int d: c),不過這樣就不能指派值了。

好啦,還是補一下for-each的版本:

public class Array99{
public static void main(String[] args){
int[][][] A={{{15,50,65},{38,94,25},{79,44,19},{89,54,73}},
    {{14,90,46},{43,23,67},{32,56,78},{94,78,40}}};
    showArray(A);
    showArray(A);
}
public static void showArray(int[][][] a){
for(int[][] i: a){
for(int[] j: i){
for(int k=0; k<j.length; k++){     //這裡如果用for(int k: j)會無法指派值
System.out.print(j[k]+ " ");
if(j[k]>=50) j[k] = 99;
}
System.out.println();
}
}
System.out.println();
}
}

Euler的圓周率


public class Pi{
public static void main(String[] args){
System.out.println("Euler(10)=" +Euler(10));
System.out.println("Euler(100)=" +Euler(100));
System.out.println("Euler(1000)=" +Euler(1000));
}
public static double Euler(int n){
boolean isPrime;
double sum = 1.0;
int count = 0;
int i = 3;
while(count < n){
isPrime = true;
for(int j=3; j<=Math.sqrt(i); j+=2){
if(i%j == 0){
isPrime = false; break;
}
}
if(isPrime){
if((i-1)%4 == 0) sum *= i / (double)(i+1);
else sum *= i / (double)(i-1);
count++;
}
i += 2;
}
return sum * 2;
}
}

數字反轉


請利用eclipse打一支程式
題目如下:
實作一個public static int reverse(int n)方法, 將一個5位數的數字逆轉. EX: 呼叫 reverse(12345) 會得到一個 54321 的結果. (提示: 可利用求餘數的方法將五個數字分別切割出來, 然後再逆轉組合. 12345 % 10 = 5)

PS:用method做

-----------------------------------

public class ReverseNum{
public static int reverse(int n){
String wn = "";
wn += n;
StringBuilder sbd = new StringBuilder(wn);
sbd.reverse();
return Integer.parseInt(sbd.toString());
}
public static void main(String[] args){
System.out.println(reverse(12345));
}
}


Java的樂透問題


拜託在後面寫一下解釋~謝謝
1.
請設計一個程式會進行樂透的開獎&對獎的過程。也就是程式會要求使用者輸入6個1~49的相異整數,代表欲對獎的彩券號碼。然後產生6個相異整數,代表某期大樂透開獎的號碼。接著程式會對獎之,並分別輸出開獎號碼、彩券號碼(均小至大排列)及中了幾個號碼!如:
請輸入你的彩券第1個號碼(1~49)
32
請輸入你的彩券第2個號碼(1~49)
4
請輸入你的彩券第3個號碼(1~49)
31
請輸入你的彩券第4個號碼(1~49)
16
請輸入你的彩券第5個號碼(1~49)
28
請輸入你的彩券第6個號碼(1~49)
2
本期開出的號碼(由小至大排列)是:4,7,16,28,33,49
你的彩券的號碼(由小至大排列)是:2,4,16,28,31,32
你中了3個號碼

----------------------------------------------

import java.util.*;
public class BigMoney{
public static final int GUESS = 6;
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int[] input = new int[GUESS];
int[] number = new int[GUESS];
int get = 0;
makeNum(number); //產生樂透號碼

for(int i=0; i<input.length; i++){
System.out.print("請輸入你的彩券第" +i+ "個號碼(1~49):");
input[i] = Integer.parseInt(sc.nextLine()); //將輸入轉成整數存入陣列
for(int j=i; j>0; j--){
if(input[i] == input[j-1] || input[i] > 49){
System.out.println("輸入重複或超出範圍");
i--;
break;
}
}
}

Arrays.sort(number); //陣列做排序
System.out.print("本期開出的號碼(由小至大排列)是:");
for(int i: number) System.out.print(i+ " ");

Arrays.sort(input);
System.out.print("\n你的彩券的號碼(由小至大排列)是:");
for(int i: input){
for(int j: number) if(i == j) get++; //計算有中的號碼
System.out.print(i+ " ");
}
System.out.println("\n你中了" +get+ "個號碼");
}

public static void makeNum(int[] n){
for(int i=0; i<n.length; i++){
n[i] = (int)(Math.random()*49+1);
for(int j=i; j>0; j--){
if(n[i] == n[j-1]){
i--;
break;
}
}
}
}
}

2012年12月2日 星期日

linux防火牆設定

安裝 # yum install system-config-firewall-tui
執行 # system-config-firewall-tui

參考自這裡

2012年12月1日 星期六

CentOS最小安裝之後

照鳥哥的書安裝了CentOS 6之後,發現書上寫的指令對我的linux根本沒作用,對我來說太複雜了。這裡記錄一下簡單一點的設定:

一、先搞上網:
#ifconfig eth0 192.168.1.101 netmask 255.255.255.0
#route add default gw 192.168.1.1
# echo "nameserver 168.95.1.1" > /etc/resolv.conf
最後一項一定要做,不然連不出去;然後鍵盤跟monitor就可以收起來了。

二、在Mac裡用終端機ssh登入:
$ ssh root@192.168.1.101
它會問yes or no?答yes(廢話)
root@192.168.1.101's password: 輸入root的密碼就可以登入了。

三、安裝圖形設定介面並執行
# yum install system-config-network-tui
# system-config-network-tui
把dhcp的星號取消(按空白鍵)


 四、最後設定,剛才的設定開機就不會不見了。
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
把ONBOOT=no改成yes

DEVICE=eth0
HWADDR=00:1a:4d:5a:1c:ff
NM_CONTROLLED=yes
ONBOOT=yes
IPADDR=192.168.1.101
BOOTPROTO=none
NETMASK=255.255.255.0
TYPE=Ethernet
GATEWAY=192.168.1.1
DNS1=168.95.1.1
IPV6INIT=no
USERCTL=no


五、好了。

參考自這裡