![](/img/trans.png)
[英]Java - How would I return an exception if the user enters a invalid input?
[英]If the user enters a blank space as their input, how would you read that as a “ ” string?
//Example: Scanner scanner = new Scanner(System.in); String character = scanner.next(); //User hits the space bar and hits enter System.out.println(character); //character should = " "
scanner.next()
為您提供下一個完整的令牌,其定義如下:
一個完整的標記前后是匹配分隔符模式的輸入。
如果你想要空間,我假設你想要整條線。 您應該告訴掃描儀獲取整行或將掃描儀的分隔符設置為換行符。 請參閱scanner.nextLine()
和scanner.useDelimiter()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.