如何使程序读取带空格的字符串输入? [英] How do I make the program read string input with spaces?

查看:70
本文介绍了如何使程序读取带空格的字符串输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了input.nextLine(),但它仍然没有将空格作为输入。相反,单词后面的空格将是我要求的下一个输出的输入。



我尝试过:



I used input.nextLine() but still it doesn't count spaces as input. Instead, word after spaces will be the input for next output I ask.

What I have tried:

System.out.println("\nInsert new attraction\n---------------------------------");
					if(choiceAttraction==1) {
					System.out.println("[Sport]");
					System.out.print("ID: ");
					int SI = input1.nextInt();
					System.out.print("Name: ");
					String SN = input.nextLine();
					System.out.print("Operating Hours: ");
					String SH = input.nextLine();
					System.out.print("Main Activity: ");
					String SA = input.nextLine();
					System.out.print("Location: ");
					String SL = input.nextLine();
					System.out.print("Rating: ");
					double SR = input1.nextDouble();
					attraction.add(new Sport(SI, SN, SH, SA, SL, SR));

推荐答案

请,请按照以下链接:

如何阅读输入来自控制台--Java [ ^ ]

在Java中读取控制台输入的方法 - GeeksforGeeks [ ^ ]

Java教程 - 从控制台读取输入 - JavaDevNotes [ ^ ]

3种方式,用于在控制台中读取用户的输入 [ ^ ]



阅读链接的文章并尝试在代码中使用提到的方法。
Please, follow below links:
How to read input from console – Java[^]
Ways to read input from console in Java - GeeksforGeeks[^]
Java Tutorial - Read Input From Console - JavaDevNotes[^]
3 ways for reading input from the user in the console[^]

Read linked articles and try to use mentioned methods in your code.


这篇关于如何使程序读取带空格的字符串输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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