Pages

Monday, June 29, 2015

Count Circles in Numbers

count how many circle in numbers
examples:

8809 = 6 7111 = 0
2172 = 0 6666 = 4
1111 = 0 3213 = 0
7662 = 2 9312 = 1
0000 = 4 2222 = 0
3333 = 0 5555 = 0

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import java.util.*;
public class CountCircle
{
   public static void main(String args[])
   {
      int n =900082;
      int count = 0;
      //0,1,2,3,4,5,6,7,8,9
      int x[] = {1, 0, 0, 0, 0, 0, 1, 0, 2, 1};
      while (n > 0) {
          count += x[n % 10];
          n /= 10;
      }
      System.out.print(count);
   }
}

No comments:

Post a Comment