checking an integer to see if it contains a zero

前端 未结 7 1799
南方客
南方客 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:41

    You can convert it to a string and check if it contains the char "0".

    int number = 101;
    if( ( "" + number ).contains( "0" ) ) {
      System.out.println( "contains the digit 0" );
    }
    

提交回复
热议问题