输出字符串字符的总数 [英] Output the total number of String Characters
问题描述
我的问题是,如果我想获得用户输入的字符总数,我应该使用哪种方法?没有使用数组,我尝试使用.length()但它没有返回所有字符,从第一个和最后一个名称,它只返回第一个名称。
My Question is what method should I use if I wanted to get the total number of characters a user inputs? without using arrays, i tried using .length() but it did not return all characters say from the first and lastname, it only returned the first name.
以下是我的代码示例。 (请不要笑我在编程中真的很新:))
Here's an example of my code. (Please dont laugh im really new in programming :) )
System.out.print("Enter your first and last name: ");
String yourName = keyboard.next();
System.out.println("Your name has a total of " + yourName.length() + " numbers");
如果我输入说Neo Matrix,它只会返回3。
what happened was if i enter say "Neo Matrix" it would only return 3.
我感谢任何帮助。谢谢!
I appreciate any help. thank you!
推荐答案
方法 next()
只读取第一个你的名字。请尝试 nextLine()
。
The method next()
only reads the first word of your name. Try nextLine()
instead.
这篇关于输出字符串字符的总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!