如果没有为文件名输入任何内容,如何提示用户输入数据?

时间:2015-12-09 00:34:13

标签: java

public static void main(String[] args) {
    System.out.println("Input filename: ");
    Scanner sc = new Scanner(System.in);
    String input = sc.nextLine();

    while (input.length() == 0){
        System.out.println("Please enter names: ");
        String names = sc.nextLine();
        }
    }

如果不再输入NAMES,如何使程序结束?

1 个答案:

答案 0 :(得分:0)

while(input.length() == 0){   // use length() method
        System.out.println("Please enter names: ");
        String names = sc.nextLine(); //Same scanner but read names to enter into an array
        }
    }