problem 1 solved with java.
public class Euler1 {
public static void main(String[] args)
{
int sum =0;
for(int i= 0; i<1000; i++){
if(i%3==0 || i%5==0)
{
sum= sum +i;
}
}
System.out.println(sum);
}
}
Problem 2 solved with java.
public class Euler2 {
public static void main(String[] args){
int sum = 0;
int a = 0;
int b = 1;
int c = a + b;
while (c < 4000000){
if (c % 2 == 0){
sum += c;
}
a = b;
b = c;
c = a + b;
}
System.out.println(sum);
}
}
Problem 3 solved with java.
public class Euler3 {
public static void main(String[] args) {
double m = 600851475143d;
for (double n = 3; n < m; n += 2) {
while (m % n == 0) {
m = m / n;
}
}
System.out.println(m);
}
}
Problem 4 solved with java.
public class Euler4{
public static void main(String[] args){
long begin = System.currentTimeMillis();
int product = 0;
int max = 0;
// go over all of the 3digits numbers twice
for (int i=10; i <= 9999; i++)
{
for (int j=10;j <= 9999; j++)
{
// consider only the palindrom products
product = i*j;
if (isPalindrome(product) && product > max)
{
max = product;
}
}
}
long end = System.currentTimeMillis();
System.out.println(max);
System.out.println(begin-end + "ms");
}
public static boolean isPalindrome(int n)
{
StringBuffer s = new StringBuffer(String.valueOf(n));
return s.toString().equals(s.reverse().toString());
}
long end = System.currentTimeMillis();
}