Hi.
Im new to Java and attempted to increase my knowledge by working on Project Euler..I figured that If Im able to solve as many problems from the project as possible with Java I will get more familiar with its syntax and the possibilities that lie therein...
Im in problem no 1
Problem no 1:
Find the sum of numbers between 0 and 1000 that are divisible by 3 or 5 and display it
and here's my code.
The error that I keep getting is:
variable sum might not have been initialized
Im new to Java and attempted to increase my knowledge by working on Project Euler..I figured that If Im able to solve as many problems from the project as possible with Java I will get more familiar with its syntax and the possibilities that lie therein...
Im in problem no 1
Problem no 1:
Find the sum of numbers between 0 and 1000 that are divisible by 3 or 5 and display it
and here's my code.
Code:
mport java.lang.String;
import java.io.*;
public class ProjectEuler {
public static void main(String[] args) {
int sum, counter, temp;
for( counter = 0; counter < 1000; counter ++)
while (((counter % 3) == 0) | ((counter % 5) == 0))
{
sum = 0;
temp = 0;
temp = counter;
sum = sum + temp;
}
System.out.println( "The sum of the numbers is: " + sum);
variable sum might not have been initialized
Comment