我是編程世界的新手,希望有人能解決這個問題並讓我明白,輸出總是「沒有數據輸入」。爲什麼它用count ++可以正常工作;但不能用count = count ++;
public class Trial {
public static void main(String[] args){
Scanner firstno = new Scanner(System.in);
int count = 0;
double sum = 0;
System.out.print("enter first number: ");
double firstnoin = firstno.nextDouble();
while (firstnoin != 0){
sum += firstnoin;
count = count++;
System.out.print("Enter next number, or 0 to end: ");
firstnoin = firstno.nextDouble();
}
if(count == 0){
System.out.println("No data is entered.");
}
else {
System.out.println("Average of the data is: "+(sum/count)+", number of terms are "+ count);
}
}
}
你可以嘗試分配另一個變量例如int counter = count ++; System.out.println(「counter的值:」+ counter); – Blaze