java如何打印这些完整的数组?
我想打印整个数组,应该有100个单词,每个单词的计数,使用次数。如何打印整个StringArray和整个IntArray
package program6;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
public class Program6 {
static String[] stringArray = new String[100];
static int[] intArray = new int[100];
static String fileName = "myths.txt";
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File(fileName));
do {
String word = input.next();
for (int i = 0; i < 100; i++) {
stringArray[i] = word;
if (word.equals(stringArray[i])) {
intArray[i] += 1;
}
}
} while (input.hasNext());
System.out.println("Myths of Babylonia and Assyria");
System.out.println(Arrays.toString(stringArray) + Arrays.toString(intArray));
}
}
# 1 楼答案
使用^{} :
还要注意的是,约定要求变量采用驼峰式大小写,类以大写字母开头。进一步注意,只有在索引到数组中或声明数组的初始大小时,才需要使用括号
# 2 楼答案
而不是
你需要迭代你的数组,也许像这样-