package com.sun;
import java.io.Console;
public class ConsoleDemo {
public static void main(String[] args) {
Console cnsl = null;
String alpha = null;
try{
// creates a console object
cnsl = System.console();
// if console is not null
if (cnsl != null) {
// read line from the user input
alpha = cnsl.readLine("Name: ");
// prints
System.out.println("Name is: " + alpha);
// read password into the char array
char[] pwd = cnsl.readPassword("Password: ");
// prints
System.out.println("Password is: "+pwd);
}
}catch(Exception ex){
// if any error occurs
ex.printStackTrace();
}
}
}
在IDE中控制台没有显示,在CMD里运行找不到或无法加载主类,没办法使用啊求帮解答!!!多谢了