Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何计算Java数组用户输入中的字符数?_Java_String_Input_Character - Fatal编程技术网

如何计算Java数组用户输入中的字符数?

如何计算Java数组用户输入中的字符数?,java,string,input,character,Java,String,Input,Character,帮助我想知道用户在这个程序代码中输入了多少个字符 此代码要求用户输入5个名称,并知道名称的字符数。我尝试使用for循环作为计数器来输出使用的字符 是否可以使用此代码的方法?我被难住了( import java.util.Scanner; 公共类ArrayDec2_Baban{ 公共静态void main(字符串[]args){ int ctr=0; 字符串arrayname[]=新字符串[5]; 扫描仪输入=新扫描仪(系统输入); System.out.println(“此程序将要求您输入5个名

帮助我想知道用户在这个程序代码中输入了多少个字符

此代码要求用户输入5个名称,并知道名称的字符数。我尝试使用for循环作为计数器来输出使用的字符

是否可以使用此代码的方法?我被难住了(

import java.util.Scanner;
公共类ArrayDec2_Baban{
公共静态void main(字符串[]args){
int ctr=0;
字符串arrayname[]=新字符串[5];
扫描仪输入=新扫描仪(系统输入);
System.out.println(“此程序将要求您输入5个名称,其中每个名称将被计数,并显示每个名称的长度。”);
System.out.println(“请输入5个名称:”);

for(inti=0;i获取了您的代码并在IntelliJ中进行了检查。缺少了一些您所猜测的简单内容


在下一行:
for(int j=0,count=0;j可以从字符串中删除所有非字母字符,然后使用length返回字符串中的字母数

int[] count = new int[arrayname.length];
for(int i = 0 ; i < arrayname.length; i++){
     count[i] = arrayname[i].replaceAll("[^a-zA-Z]", "").length();
}
//count[0] holds the size of the first name
//count[1] holds the size of the second name
//...
int[]count=new int[arrayname.length];
for(int i=0;i
为什么您认为有问题?我在运行时出错:(我将尝试使用IntelliJ,我现在正在使用记事本+)。谢谢。但是有一个问题,我可以使用Character.IsLength作为方法并将其返回到main方法吗?将其更改为其他值,运行时仍有错误,仅打印1 2 3 4 5。我不确定方法问题,因为我刚刚开始。我有同样的问题,我只是将代码嵌入IDE(打印12345).但让jint[] count = new int[arrayname.length]; for(int i = 0 ; i < arrayname.length; i++){ count[i] = arrayname[i].replaceAll("[^a-zA-Z]", "").length(); } //count[0] holds the size of the first name //count[1] holds the size of the second name //...