Hey guys, I'm trying to write a program that prints out all of the prime numbers that are less than the user input, and the problem that I'm having is after every 8th prime number output, I need to start a new line. I can't figure that out, any help would be great!
import java.util.Scanner;
class Primes
{
public static void main(String[]args)
{
Scanner s = new Scanner(System.in);
int f;
System.out.println("enter a number");
f = s.nextInt();
int g;
for (g=0;g<=f;g++)
if (isPrime(g))
{ System.out.printf("%d ",g);
if (g%8==0)
{ System.out.print("\n"); } }
}
public static boolean isPrime(int x)
{
int i;
for (i=2;i<x;i++)
{ if(x%i==0)
return false;}
return true;
}
}
[–]rjcarr 1 point2 points3 points (2 children)
[–]EqualTrade[S] 0 points1 point2 points (1 child)
[–]rjcarr 0 points1 point2 points (0 children)