I need help with my java program. This program will generate Prime numbers. Class testerPrime will invoke Class Prime. Everything is working but i need my output to print in 10 columns then go to the next line. Here's my code

Class Prime

class Prime {
     	int number;
      int numPrime=0;
		int i;
		
		public void setnumber(int Number){
         number = Number;
			}
		public void setnumPrime(int NumPrime){
         numPrime = NumPrime;
			}
					
		public String isPrime() {
		int numCount = 0;
		// candidate:  the number that might be prime
		int candidate = number;
		System.out.println("First " + numPrime + " primes:");
			while (numCount < numPrime) {//This is the loop that determines how many
				if (isPrime(candidate)) { //Prime number should be displayed
				System.out.print(candidate + " ");
				numCount++;//increments numCount by 1
				}
			candidate++;//increments candidate by 1
			}
		return "";
		}
 		
		//This method checks the number if it's Prime or not
		public boolean isPrime(int number) {
		double root = Math.sqrt(number);
		
			
			for ( i = 2; i <= root; i++) {   
      		for(int j=0; j<= 5;j++)
				{
					if (number % i == 0) {
					return false;
					}
				}
				System.out.println();	
			}
			//System.out.println();
			return true;
			
		}
			  
	}

Class testerPrime

import java.util.*;
	

    class testerPrime{
       public static void main(String[] args){
         int number;
         int numPrime;	
         Scanner myScanner = new Scanner(System.in);
      
         do
         	{
               
					System.out.println("\nEnter Starting Prime Number(1 to quit): ");
               number = myScanner.nextInt();
				   
					if(number!=1){
						System.out.println("How many Prime should be generated?  ");
               	numPrime = myScanner.nextInt();
						Prime myPrime = new Prime();
						myPrime.setnumber(number);
						myPrime.setnumPrime(numPrime);
						System.out.format(myPrime.isPrime());        
         		}
					          
      	}
      while(number!=1);	
						
		System.out.println("\nBye");
		
		}
		
   }

can upload one without the prime numbers ?

It's this right here

for ( i = 2; i <= root; i++) {   
      		for(int j=0; j<= 5;j++)
				{
					if (number % i == 0) {
					return false;
					}
				}
				System.out.println();	
			}

get rid of the

System.out.println();

It's makes a newline every time the second loops finishes.

this post was answered. pls dont reply anymore

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.