输出字符串字符的总数 [英] Output the total number of String Characters

查看:134
本文介绍了输出字符串字符的总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,如果我想获得用户输入的字符总数,我应该使用哪种方法?没有使用数组,我尝试使用.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屋!

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