import java.util.Scanner;
public class DivisibleBy6or17 {
public static void main(String[] args) {
Scanner kbd = new Scanner (System.in);
System.out.print("How many Values To Read ? ");
int amount = kbd.nextInt();
int[] values = new int[amount];
int i = 0;
double divisible = 0;
int count = 0;
while (i < amount) {
System.out.print("Enter Value : ");
int nbr = kbd.nextInt();
if (nbr %6 == 0 || nbr % 17 == 0) {
divisible += nbr;
count++;
}
i++;
}
if (divisible == 0) {
System.out.print("NONE DIVISIBLE");
}
else {
System.out.print("Average: " + divisible/count);
}
}
}
所以我想要可以被16或17整除的数字的总和,那么我可以为总和插入一个if else然后为平均值做其他吗?我不知道在何处插入嵌套if语句的总和
答案 0 :(得分:0)
System.out.println(divisible);
将打印出总和,因为您只是将它们全部添加到该变量中。