checking an integer to see if it contains a zero

前端 未结 7 1791
南方客
南方客 2020-12-14 21:09

Given an integer, how could you check if it contains a 0, using Java?

1 = Good
2 = Good
...
9 = Good
10 = BAD!
101 = BAD!
1026 = BAD!
1111 = Good

How c

7条回答
  •  一个人的身影
    2020-12-14 21:40

    I don't know if this is easier but here is another way. Split the number into an array of ints. Then sort and check if the first element is zero. E.g

    int n = 14501;
    // after splitting
    int na = {1, 4, 5, 0, 1};
    // after sorting
    int na = {0, 1, 1, 4, 5};
    

提交回复
热议问题