扫描仪在空间后看不到 [英] Scanner doesn't see after space

查看:136
本文介绍了扫描仪在空间后看不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,询问该人的全名,然后接受该输入并将其反转(即John Doe - Doe,John)。我开始尝试获取输入,但它只获取名字。

I am writing a program that asks for the person's full name and then takes that input and reverses it (i.e John Doe - Doe, John). I started by trying to just get the input, but it is only getting the first name.

这是我的代码:

public static void processName(Scanner scanner) {
    System.out.print("Please enter your full name: ");
    String name = scanner.next();
    System.out.print(name);
}


推荐答案

更改为 String name = scanner.nextLine(); 而不是 String name = scanner.next();

在此处查看有关文档的更多信息 - next() nextLine()

See more on documentation here - next() and nextLine()

这篇关于扫描仪在空间后看不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆