我知道这个不起作用,但是我如何知道用户是否添加了至少一个字符?
public class Program
import java.util.Scanner;
{
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
String b = a.nextLine();
//I know this doesnt work but how can I know if the user added even one char?
if (b!=null){
System.out.println(b);
}
}
}
b.isEmpty()
。nextLine()
永远不会返回 null。 - Andy Turner