- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我如何使用 Scanner 从键盘读取一系列字符串,全部在一行上,并将它们连接起来。
这是我目前的代码:
import java.util.Scanner;
public class Exam12Practice {
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
String words="";
System.out.println("enter a word");
while(input.hasNext())
{
words = words.concat(input.next());
}
System.out.println(words);
}
}
最佳答案
您的代码已经完成了您的要求。让它工作
Type in your words
Press Enter
Press CTRL-Z (^D on *nix systems)
注意事项:
input.hasNext()
将始终为 STDIN
返回 true,因此仅按 Enter 本身是行不通的。
您可以使用 input.readLine()
并拆分单词进行练习。
大多数人可能更喜欢使用 StringBuilder
,因为它提供的性能优于 String.concat
。
关于java - 我如何使用扫描仪从键盘读取一系列字符串,全部在一行上,并将它们连接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12665835/
我正在尝试执行 vagrant up 但一直遇到此错误: ==> default: IOError: [Errno 13] Permission denied: '/usr/local/lib/pyt
我在容器 div 中有一系列动态创建的不同高度的 div。 Varying text... Varying text... Varying text... Varying text.
通过 cygwin 运行 vagrant up 时遇到以下错误。 stderr: /bin/bash: /home/vagrant/.ansible/tmp/ansible-tmp-14872260
今天要向小伙伴们介绍的是一个能够快速地把数据制作成可视化、交互页面的 Python 框架:Streamlit,分分钟让你的数据动起来! 犹记得我在做机器学习和数据分析方面的毕设时,
我是 vagrant 的新手,正在尝试将第二个磁盘添加到我正在用 vagrant 制作的虚拟机中。 我想出了如何在第一次启动虚拟机时连接磁盘,但是当我关闭机器时 然后再次备份(使用 'vagrant
我是一名优秀的程序员,十分优秀!