do{
do{
System.out.print("Enter number" + count + ":");
if(scan.hasNextInt()){
d1 = scan.nextInt();
count ++;
}
else{
System.out.print("Number is invalid. ");
scan.next();
continue;
}
t+=d1;
}while(count<=5);
total = t / 5;
System.out.print("The average is :" + total + " ." );
System.out.print(" [do you want to continue press[ y ]for yes and [ n] for no ]:");
字符串
我试着把t+=放在括号的内部和外部,但没有好的结果仍然是相同的,这部分是我感到困惑的地方,因为t+=d1将堆叠更多的我循环,例如,我所有的5个数字是25,然后平均值是25,然后我按y,然后循环回来,我输入相同的5的25,然后平均值是50
1条答案
按热度按时间rmbxnbpk1#
建议:
这是一个测试类:
字符串