

public static void main(String[] args) {
Scanner you = new Scanner(System.in);
System.out.print("请输入待检测产品数量:");
int a = you.nextInt();
System.out.println("请输入产品质量信息,质量信息用换行(回车)隔开:");
int[] b;
b = new int[a];
int c = 0;
for (int i = 0; i < a; i++) {
b[i] = you.nextInt();
if (b[i] != 1 && b[i] != 0) {
System.out.println("输入错误请重新输入");
i--;
}
if (b[i] == 1) {
c++;
}
}
double d = (double) c / a;
DecimalFormat decimalFormat = new DecimalFormat(".00");
String e = decimalFormat.format(d * 100);
System.out.println("本次受检产品合格率为:" + e + "%");
}