I am trying to format the output from what I have written to display a list of primes (Eratosthenes) to a certain number results per line. Do they need to placed into an Array
to accomplish this? I have not come across a way to implement their division besides .split("");
, which would render a single line for each and the Oracle site's System.out.format();
argument index to specify length. Yet, these require the characters to be known. I am printing it with the following, which of course creates an infinite line.
for (int count = 2; count <= limit; count++) {
if (!match[count]) {
System.out.print(count + ", ");
}
}
Is there a way to simply call System.out.print("\n");
with an if(...>[10]
condition when System.out.print()
has run for instance 10 times? Perhaps I am overlooking something, relatively new to Java
. Thanks in advance for any advice or input.
You can just simply create some int value e.g.
...and increment it's value everytime Sysout is running.
Something like this: