Statement of needs:
Write Java programs, between 1 and 100 output can be simultaneously maximum five numbers divisible by 3 and 4.
Realization of ideas:
Declare variables COUNT, the number of data satisfying the condition for setting the initial value 0.
Find data satisfying the condition in the interval from 1 to 100, need to be determined individually for each digit may be used to achieve cyclic structure.
Implementation code:
import java.util.Scanner;
public class FindMaxFiveDemo {
public static void main(String[] args) {
System.out.println("1~100之间能够同时被3和4整除的最大的五个数字:");
int count = 0; //满足条件的数据个数
for(int i = 100; i > 0; i--) {
if(i % 3 != 0 || i % 4 != 0) {
continue; //不满足条件的数据个数
System.out.println("");
count++; //数据个数累加1
}
if(count >= 5) {
break; //达到五个数字,跳出循环,不在继续查找
}
}
}
}