我试图在每次用户输入“是”时添加 25,然后打印结果,但在添加它们时它总是缺少第一个响应。那么,如果我对乳制品输入“是”,我只能得到 75% 的结果?这是针对较大代码段的一项正在进行的工作,但基本上目前如果您为乳制品输入“是”,那么它应该将它们全部加起来并等于 100。
尝试了很多不同的选择,却一无所获
import java.util.Arrays;
import java.util.Scanner;
public class question4 {
public static void main(String[] args) {
Scanner userTypes = new Scanner(System.in); //new object for user input
String[] respondents = {"Cormac", "Orla", "Paul", "Sarah"};
String[] questions = {"Are you allergic to Dairy?", "Are you allergic to nuts?", "Are you gluten intolerent?"};
String[] decisions = new String [4];
int dairy= 0;
int nuts= 0;
int gluten=0;
for (int i=0; i<= respondents.length -1 ;i++) {
System.out.println(respondents[i]);
for (int j=0; j<= questions.length -1; j++) {
System.out.println(questions[j]);
decisions[j]=userTypes.nextLine();
}
System.out.println(Arrays.toString(decisions));
}
System.out.println("Allergy Results");
for (int k=0; k <= respondents.length - 1; k++ ){
if (decisions[k].equals("Yes")) {
dairy= dairy + 25;
}
}
System.out.println("Dairy Allergy Results = " + dairy + "%");
}
}
慕工程0101907
阿波罗的战车
Helenr
相关分类