I need help with my java program. I can't seem to figure out how to print my output in 10 numbers and then go to the next line. For example:
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16

here's my code

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;
			
		}
			  
	}

after numCount++;
but before you close that loop, just add if(numCount%10 == 0)
System.out.println(""); // or System.out.print("\n");

This article has been dead for over six months. Start a new discussion instead.