java - Adding a new object to an array according to loop returns -


i did research on subject (i'm quite new java excuse me poor/incorrect wording) , didn't find related answers, so, here goes.

i'm working on program can print prime numbers , ran following problem.

here's code:

public class pnumba {      public static void main(string[] args) {          int pnlimit = 100;         system.out.println("printing prime numbers");         (int numer = 2; numer <= pnlimit; numer++) {             if (checkforprime(numer)) {                 system.out.println(numer);             }          }     }      public static boolean checkforprime(int numer) {         (int = 2; < numer; i++) {             if (numer % == 0) {                 return false;             }         }         return true;     } } 

my program prints prime numbers up 100 , not 100 of them. idea make array hold 100 prime numbers , break loop when said array reaches limit fix problem.

my questions following:

  1. how make loop fill array when checkforprime() method returns true?
  2. do have use break; stop loop when reaches 100 prime numbers?
  3. can use <=arrayname.length stop for loop alternative?

please tell me if need more info.

change main block follow:

int counter = 1; system.out.println("printing prime numbers");  (int numer = 2; counter <= 100; numer++){     if (checkforprime(numer)) {         system.out.println(numer);         counter++;     }  } 

here counter execute loop until 100 prime numbers displayed...............!


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

how to receive file in java(servlet/jsp) -