The others have pointed out many things, but I have one thing to add:
Instead of using the +
operator for accumulating a total, thus having to write the left-hand operand twice, you can use the +=
operator instead.
For instance, instead of
number = number + 2;
you'll have
number += 2;
The relevant statements would look like this. I'll also apply some of @palacsint's suggestions so that you can see the improved code together.
for (double x = 1; x > 0.000; x += 1.000) {
// ...
for (double multiplier = 1.000; multiplier <= (x); multiplier += 1.000) {
// ...
primeLogger += 1.000;
// ...
}
}
Although those three variables should just be incremented by one with ++
(based on @Uri Agassi's advice), I've shown the use of +=
here just for demonstration. For values other than one (which only works with ++
or --
), you would use +=
.
The others have pointed out many things, but I have one thing to add:
Instead of using the +
operator for accumulating a total, thus having to write the left-hand operand twice, you can use the +=
operator instead.
For instance, instead of
number = number + 2;
you'll have
number += 2;
The relevant statements would look like this. I'll also apply some of @palacsint's suggestions so that you can see the improved code together.
for (double x = 1; x > 0.000; x += 1.000) {
// ...
for (double multiplier = 1.000; multiplier <= (x); multiplier += 1.000) {
// ...
primeLogger += 1.000;
// ...
}
}
The others have pointed out many things, but I have one thing to add:
Instead of using the +
operator for accumulating a total, thus having to write the left-hand operand twice, you can use the +=
operator instead.
For instance, instead of
number = number + 2;
you'll have
number += 2;
The relevant statements would look like this. I'll also apply some of @palacsint's suggestions so that you can see the improved code together.
for (double x = 1; x > 0.000; x += 1.000) {
// ...
for (double multiplier = 1.000; multiplier <= (x); multiplier += 1.000) {
// ...
primeLogger += 1.000;
// ...
}
}
Although those three variables should just be incremented by one with ++
(based on @Uri Agassi's advice), I've shown the use of +=
here just for demonstration. For values other than one (which only works with ++
or --
), you would use +=
.