我試圖確保我的程序不會計爲零作爲偶數,並且明確寫道它必須符合這些條件。但它仍然算它!?!?程序計數0甚至
import java.util.Scanner;
public class CountDigits
{
public static void main (String []Args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter a number:");
long input = (keyboard.nextLong());
String inputString = Long.toString(input);
char [] inputChar = (inputString.toCharArray());
int numOdds = 0;
int numEvens = 0;
int numZeros = 0;
int i = 0;
while (i<inputString.length())
{
if (inputChar[i]!=0&&inputChar[i]%2==0)
{
numEvens++;
}
什麼是'inputChar'和什麼是'inputString'?分享完整的代碼 –
你有沒有試過將'inputChar'轉換爲數字? – Wazaaaap