我将如何运行这段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中右键单击&gt;&gt;运行....
...了 跑: 构建成功(总时间:0秒)
答案 0 :(得分:1)
Oracle has a tutorial. 在终端试试这个:
javac login.java
java login
答案 1 :(得分:1)
假设代码位于名为login.java的文件中......
编译:
javac login.java
应生成login.class,运行时为:
java login
答案 2 :(得分:0)
“输出”窗口通常也是您的控制台窗口。尝试使“输出”窗口可见。
对于C ++,there is an option in Netbeans for where Console should read from。