如何逐步计算字符串数组中的字符数? -Java
How to progressively count the number of characters in a String Array? -Java
我是一名没有编码经验的大一学生。我正在为我的第二个任务开发一个文本编辑器。此文本编辑器的众多功能之一是能够计算字符串中的字符数,并且由于这是一个字符串数组,因此有多个。这是我到目前为止得到的:
int maxSize=100;
int [] nChars = new int[maxSize];
String [] linhas = new String[maxSize];
for (int i=0; i<maxSize;i++){
nChars[i]=lines[i].charAt(i);
System.out.println(lines[i]+ " - " + nChars[i]); \print the line and the respective number of characters
感谢任何帮助,我几乎被困住了。
您正在搜索的函数只是 .legth() 函数,它将 return 字符串中的字符数。
String myString = "testString";
System.out.println("The string has " + myString.length() + " characters");
// output: The string has 10 characters
如果您有一个字符串数组,则只需遍历它并对每个元素使用 length() 函数。
问候乌鸦
我是一名没有编码经验的大一学生。我正在为我的第二个任务开发一个文本编辑器。此文本编辑器的众多功能之一是能够计算字符串中的字符数,并且由于这是一个字符串数组,因此有多个。这是我到目前为止得到的:
int maxSize=100;
int [] nChars = new int[maxSize];
String [] linhas = new String[maxSize];
for (int i=0; i<maxSize;i++){
nChars[i]=lines[i].charAt(i);
System.out.println(lines[i]+ " - " + nChars[i]); \print the line and the respective number of characters
感谢任何帮助,我几乎被困住了。
您正在搜索的函数只是 .legth() 函数,它将 return 字符串中的字符数。
String myString = "testString";
System.out.println("The string has " + myString.length() + " characters");
// output: The string has 10 characters
如果您有一个字符串数组,则只需遍历它并对每个元素使用 length() 函数。
问候乌鸦