Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要存储来自命令提示符的用户输入,例如,如果用户键入“hello 23”
我需要检查“你好”并将 23 存储在单独的整数中
将用户的输入视为一个字符串,您应该将其拆分为空格,然后解析第二个元素。
Scanner in = new Scanner(System.in); String userInput; userInput = in.nextLine(); String[] arrayOfStrings = userInput.split("\\s+"); Integer number = Integer.parseInt(arrayOfStrings[1]);
Console.readline()
String.split("\s+")
整数.parseInt()