引用 | 編輯
panasonic732
2006-11-12 21:58 |
1樓
▲ ▼ |
這一題是否能請您自己想一下
大致上只要使用 變數 輸入 if 先想想看喔 x0 |
引用 | 編輯
PeterPan
2006-11-13 17:50 |
3樓
▲ ▼ |
複製程式
public class Test{ public static void main(String[] args) throws Exception{ Test t = new Test(); String stPassword = "0123"; int iTryTime=0,iTryLimit=3; boolean bSuccessLogin = false; java.io.BufferedReader input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); System.out.print("user login..\r\n"); do{ System.out.print("please enter password:"); String stTemp = input.readLine(); if(stTemp==null || !stTemp.equals(stPassword)){ iTryTime++; System.out.print("error password, access denied!\r\n"); } else{ bSuccessLogin = true; break; } }while(iTryTime<iTryLimit); if(bSuccessLogin){ System.out.print("\r\nlogin success."); } else{ System.out.print("\r\nlogin fail."); } } } 我又害了一個學生 x0 |