# 迅雷编程题：编程:求一个数除2余1 除3余2 除4余3 除5余4 除6余5 除7余0

package com;

public class Test {
public static void main(String []args){
System.out.println(getSteps1());
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
System.out.println(Test.getSteps());
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
public static int getSteps(){//利用最小公倍数，来减少遍历次数。
int i=1;
int step=2;
boolean maxStep=false;
while(true){
System.out.print(" "+i+" ");
if(!maxStep){
if(i%2==1){step=2;}else{i+=step;continue;}
if(i%3==2){step=6;}else{i+=step;continue;}
if(i%4==3){step=12;}else{i+=step;continue;}
if(i%5==4){step=60; maxStep=true;}else{i+=step;continue;}
if(i%6==5){step=60; maxStep=true;}else{i+=step;continue;}
if(i%7==0){ return i;}else{i+=step;continue;}
}else{ //以后每次加60
if(i%7==0){return i;}else{i+=step;}//else{i+=step;continue;}加了一个continue 编译器出错。
if(i%6==5){}else{i+=step;continue;}
if(i%5==4){}else{i+=step;continue;}
if(i%4==3){}else{i+=step;continue;}
if(i%3==2){}else{i+=step;continue;}
if(i%2==1){}else{i+=step;continue;}
}
}
}

public static int getSteps1(){
int i=1;
while(true){
if(i%2==1){}else{i++;continue;}
if(i%3==2){}else{i++;continue;}
if(i%4==3){}else{i++;continue;}
if(i%5==4){}else{i++;continue;}
if(i%6==5){}else{i++;continue;}
if(i%7==0){return i;}else{i++;continue;}
}
}
}

119
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1  3  5  11  23  35  47  59  119 119
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

• 本文已收录于以下专栏：

举报原因： 您举报文章：迅雷编程题：编程:求一个数除2余1 除3余2 除4余3 除5余4 除6余5 除7余0 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)