我想简化以下法典:
public static void main(String[] args) {
int c1 = Integer.parseInt(args[0]);
int c2 = Integer.parseInt(args[1]);
int c3 = Integer.parseInt(args[2]);
/* 1 */if (c2 - c1 == 0) {
/* 2 */if (c1 != c3) {
c3 += c1;
/* 4 */System.out.println(c3);
/* 5 */c3 *= c2;
/* 6 */}
}
/* 7 */if (c1 == c3)
/* 8 */if (c1 - c2 == 0)
/* 9 */{
c3 += c1;
/* 10 */System.out.println(c3);
/* 11 */c3 *= c1;
/* 12 */if (c1 < c2)
c2 += 7;
/* 13 */else
c2 += 5;
/* 14 */}
/* 15 */System.out.println(c1 + c2 + c3);
}
第一<代码>c2 - c1 = 0与c2 = c1
和c1 - c2 = 0
相同。 除此以外,我还可以删除<代码>if (c1 < c2),并保留其他说明的内容。
结果:
public static void main(String[] args) {
int c1 = Integer.parseInt(args[0]);
int c2 = Integer.parseInt(args[1]);
int c3 = Integer.parseInt(args[2]);
/* 1 */if (c1 == c2) {
/* 2 */if (c1 != c3) {
c3 += c1;
/* 4 */System.out.println(c3);
/* 5 */c3 *= c2;
/* 6 */}
}
/* 7 */if (c1 == c3)
/* 8 */if (c1 == c2)
/* 9 */{
c3 += c1;
/* 10 */System.out.println(c3);
/* 11 */c3 *= c1;
c2 += 5;
/* 14 */}
System.out.println(c1 + c2 + c3);
}
My question is what could be simplified now? If the inner if would be outside I could simplify the if s. What do you think?