public class ProjectOne
{
public static void main (String[] args)
{
int i, count1 = 0, count2 = 0, count3 = 0;
int sum1 = 0, sum2 = 0, sum3 = 0, total;
for(i=1; i<1000; ++i) //creates loop that will iterate for every number
{
if (i%3 == 0)
count1 += 1; //gathers total #'s <1000 that can be divided by 3
if (i%5 == 0)
count2 += 1; //same as above, but divisible by 5
if (i%3 == 0 && i%5 ==0)
count3 += 1; //gathers count for where sets intersect
for (i=1; i<=count1; ++i)
sum1 += 3*i; //creates sum for all multiples of 3
for (i=1; i<=count2; ++i)
sum2 += 5*i; //creates sum for all multiples of 5
for (i=1; i<= count3; ++i)
sum3 += 15*i; //creates sum for where sets intersect
}
total = (sum1 + sum2) - sum3; //totals two sums while subtracting
//the intersections that would double
System.out.print (total); // prints total value
}
}
Okay so I'm running through Project Euler trying to work on some of coding skill and mathematics (I'm relatively new and am learning Java for a class). Either way, I create this piece of code that is supposed to sum all of the multiples of 3 and 5 that are less than 1000. I go to compile the code and it compiles just fine but when I go to run it the command prompt (I'm running Windows 8.1 by the way) sits there doing nothing and responding to nothing, the cursor just sitting there blinking. I'm used to programming using Python's IDLE and so have little practice with command prompt. Am I just being impatient or is there something that is not functioning quite the way it should?
iin the loop. At the end of every loop iteration,i = count3+1.