Hardik Sirvi Hardik Sirvi - 1 year ago 67
Java Question

About a Looping Program in Java

I need a Program in Java in which I can give any number to the program and in return it tells me that how many odd or even digits are present in that number.
for Example:- I give - 1234567,then it tells me that Even-3 digits and Odd - 5 digits Thank You

Answer Source
public class Count
  public void display(int number)
   int a,nOdd =0 ,nEven=0;
   while(number > 0)
     a = number % 10;
     nEven ++;
     nOdd ++;
     number = number / 10;
  System.out.println("No. of Odd digits = "+nOdd);
  System.out.println("No. of Even digits = "+nEven);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download