我正在尝试一个尝试对 3 个等级(3 个文本框)求和的代码,当您单击“计算”按钮时,3 个值被求和并除以 3,(1 个平均等级文本框)
当我验证第二个和第三个文本框是否为空时,我的错误出现了,它应该只取第一个文本框并从中获得平均成绩。
int p1,p2,p3,promedio;
p1=Integer.parseInt(par1.getText()); //getting the grade1 textbox info and parsing to int
p2=Integer.parseInt(par2.getText()); //same , grade2
p3=Integer.parseInt(par3.getText()); //same, grade3
promedio=((p1+p2+p3)/3); //summing and dividing to 3
String pp = String.valueOf(promedio); //parsing avarage grade to string
pro.setText(pp); //printing the avarage grade to his respective textbox
String pp1 = String.valueOf(p1); //parsing the 3 grades to strings, to i can validate later
String pp2 = String.valueOf(p2);
String pp3 = String.valueOf(p3);
if(pp2.isEmpty() && pp3.isEmpty()){ //if grade 2 and 3 are empty
pp = pp1; //avarage grade = p1 (grade 1)
pro.setText(pp); //printing avarage grade
}
我不知道我做错了什么。