【发布时间】:2015-09-08 16:16:58
【问题描述】:
我写了一个计算单词最大排列数量的方法,但 IntelliJ IDEA 给了我警告:
从未使用分配给“permutationAmount”的值长度 - 1
private static int permutationsPossible(String word) {
//Amount of letters in word.
int length = word.length();
//Return length if length is less than or equal to 1.
if (length <= 1)
return length;
//Calculate maximum amount of permutations.
int permutationAmount = length;
for (int i = 1; i < length - 1; i++)
permutationAmount *= (length - i);
return permutationAmount /= length - 1;
}
但是,当我像这样创建 helper int 时不会显示警告:
permutationAmount = permutationAmount /= length - 1;
return permutationAmount;
该程序双向运行都很好,我只想知道,为什么 IntelliJ 会警告我从未使用过 'length - 1'?
【问题讨论】:
-
你做了一个没有必要的赋值,因为你从不直接从被覆盖的变量赋值后使用这个新值。
标签: java intellij-idea int warnings helper