今天寫了一段代碼用來測試輸入,發現不管怎么樣搜無法輸入數據,代碼如下:
@Test
public void func01(){
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()){
String msg = scanner.nextLine();
System.out.println(msg);
}
}
感覺寫得沒有錯,以前也能運行,但是就是不能輸入,后來發現這段代碼是在單元測試里面運行的,只要把這段代碼放到main函數里面就能運行了