我这里有这段代码,输出带有null
。我怎样才能删除它?
输入是:
hello hello i i am norman
for (int i=0; i<words.length; i++){
boolean isUnique = true;
int freq = 0;
for (int j=0; j<words.length; j++){
if (i==j){
freq++;
continue;
}
if (words[j].equals(words[i])){
isUnique = false;
freq++;
}
}
if (isUnique){
uniquewords[i] = words[i];}
frequency[i] = freq;
}
}
输出:
null null null null am norman
最佳答案
if (uniquewords[i] != null){
System.out.println(uniquewords[i]);
}
打印时添加此检查
关于java - 如何仅使用数组和循环(没有其他方法)来删除 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59195275/