ranjan's techblog

October 29, 2008

Project Euler – Problem 5

Filed under: Uncategorized — Tags: , , — ranjan @ 10:46 am

Problem 5 was easy, but was taking a long time in Python. So I tried it in Java, it took around 8 min to get the answer.

Here’s the code.

public class Problem5 {

public static void main(String[] args) {
Problem5 prob = new Problem4();
double number = 1.0;
while ( !prob.isDivisible(number)){
number += 1;

}

System.out.println( “————-” + number );

}

public boolean isDivisible( double number ){
boolean div = true;

for( int i =1; i <= 20 ; i ++) {
if (number % i != 0){
div = false;
}
}

return div;

}
}

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.