簡體   English   中英

如果用戶輸入一個空格作為他們的輸入,你會如何將其讀為“ ”字符串?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM