How can I count how many digits in an inputted integer are even and how many are odd?
for example if the user entered number: 1234567
The output should be: 3 digits are even and 4 digits are odd.
I think I have to use a loop, but I don't know what to put the condition.
Any help?
int num = 0;
int countEven = 0;
int countOdd = 0;
num = num%10;
if(num/2==0){
countEven++;
}
else{
countOdd++;
}
System.out.print(countEven+" "+countOdd);

New Topic/Question
Reply



MultiQuote









|