愛因斯坦階梯

package TestSuanFa;

/**
 * 愛因斯坦階梯
 * 
 * @author Joy
 * 
 */
public class JieTi {
	public static int jieti(){
		int count = 0;  //階梯總數
		int result =0;  //找到階梯結果儲存值
		for (int i = 0; i <= 100; i++) {
			if ((count%2==1)&&(count%3==2)&&(count%5==4)&&(count%6==5)&&(count%7==0)) {
				result = count;   //找到結果
				break;
			}
			count=i*7;   //沒有找到繼續循環
		}		
		return count;		
	}
	
	
public static void main(String[] args) {
	System.out.println("愛因斯坦階梯問題求解!");
	int num=jieti();
	System.out.println("這個階梯共有"+num+"個臺階");
}
}
相關文章
相關標籤/搜索