我將如何運行這段java代碼?使用System.console運行java代碼類
import java.io.Console;
import java.util.Arrays;
/**
*
* @author User
*
*/
public class login{
boolean authenticate(String u,char[] c){
boolean x = false;
if(u=="soumitra"&&c.toString()=="paas")
{ x=true;}
return x;
}
public boolean login()
{int MAX_LOGINS=2;
Console con = System.console();
boolean auth = false;
if (con != null)
{
int count = 0;
do
{
String uname = con.readLine("Enter your username: ");
char[] pwd = con.readPassword("Enter %s's password: ", uname);
auth = authenticate(uname, pwd); // authenticate login info
Arrays.fill(pwd, ' '); // delete password from memory
con.writer().write("\n\n"); // output a couple of newlines
} while (!auth && ++count < MAX_LOGINS);
}
return auth;
}
public static void main(String args[]){
login obj=new login();
obj.login();
}
}
試圖在Netbeansby rightclicking運行>>運行....
了... 運行: BUILD SUCCESSFUL(總時間:0秒)
可能的重複http://stackoverflow.com/questions/2159655/compile-and-run-this-java-program – nes1983
你也可以看看java的命名習慣......學習的時候好習慣。登錄應該以大寫字母開頭 – Snicolas