我正在處理一個簡單的java代碼,輸出用戶輸入數字的所有因素。如何計算並顯示輸出的因素數量?輸出中的整數數量?簡單的java程序
System.out.println("Enter an integer to be factored:");
int d = Stdin.readInt();
System.out.println("The Factors of " + d + " are:");
for(int w = 1; w <= d; w++){
if(d % w == 0){
System.out.println(w);
}
}
在上面的代碼,它在「W」輸出例如整數的數字,如果輸入的號碼是8和它的因素是1,2,4,8,我怎麼寫代碼,說'8有4個因素'?
感謝