I have a working code that gives me the prime numbers but I want it to print out either a - if it not a prime and if it is a prime print the prime. I have that working but I can not get it to stop at 10 and then go to the next line. I have tried several diffrent ways of the if (i%10==0) System.out.prin tln(); but to no avail. Please help.
Here is most the code I have.
Here is most the code I have.
Code:
int a=0;// int intializing a=0
int b=0;// int intializing b=0
public static void main(String... args)
{ //start main method
Scanner input = new Scanner(System.in);//renamed Scanner to input
System.out.print("Enter the Starting Number of the Range: ");// print line
int a = input.nextInt();// gets starting range from user
System.out.print("Enter the Ending Number of the Range : ");//print line
int b = input.nextInt();//gets upper range from user
System.out.println(dash);// prints a line of dashes
for(int i = a; i <= b; i++) //this is the primer for the prime number formula
{
boolean isPrime = true;//sets the statement to true
if (isPrime)
for(int j = 2; j <= i; j++)//formula to get the prime
{
if(i != j && i % j == 0) //formula checking prime
isPrime =false; //sets statement to false
}
if (isPrime)
{
System.out.print(i+" ");//if true it prints prime number
System.out.print("-"+" ");//if false it prints a dash
}
}
}//end of main method
}//end of class
Comment