In java, the return value is 3 in-, and the number of digits is 6, and the value is -.
/* The number of integers in 1000-9999 that can be divided by 3 and the single digit is 6 */
Public class IntTest {
Public static void main (String [] args ){
// Instantiate an object
IntTest it = new IntTest ();
// Output the returned data
System. out. println (it. zb (1000,999 9 ));
}
Public int zb (int start, int end ){
// Declare a counting variable. The initial value is 0.
Int flag = 0;
For (int I = start; I <= end; I + = 2 ){
// As long as it is divided by 3, the single digit is 6. Add 1 to the counter
If (I % 3 = 0 & I % 10 = 6 ){
Flag ++;
}
}
// Return the calculated value
Return flag;
}
Resolution: I + = 2; or I + = 1; I + = 2 is used because a single position of 6 is certainly divisible by 2. Reduce the number of cycles.
If you have any good methods or do not understand them, you are welcome to comment on them.