所以我正在嘗試編寫一個標記值為 0 的代碼。它提示用戶輸入數字,并找到所有輸入數字的正負和總和。我不明白為什么在我輸入標記值 0 后它不打印任何東西。我的 while 循環有問題嗎?謝謝你 !我嘗試了很多東西,但仍然看不到原因。package Csc220Study;import java.util.Scanner;public class S51 {public static void main(String [] args){ System.out.println(" enter an integer , the input ends if it is 0:"); Scanner input = new Scanner(System.in); int sum =0; int positives=0; int negatives=0; int count=0; int x = input.nextInt(); while(x!=0){ sum=+x; if(x<0){ negatives++; }else if(x>0){ positives++; } count++; } System.out.println("the sum is :"+sum); System.out.println("positive number here :"+positives); System.out.println("negative numbers are :"+negatives);
為什么我的哨兵值不起作用,我可以輸入無限的整數但什么也得不到?
慕蓋茨4494581
2022-06-04 15:41:39