Jamiemcg

Yahoo! Answers - Determine Prime Numbers from Text File

Oct 19th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. /*This code is intended to be pseudo-code, and will not work if compiled and run.
  2.  *Instead, it should be used as a starting point for writing actual code.
  3.  *Yahoo Answers Question: https://answers.yahoo.com/question/index?qid=20141019091026AAQF8qU
  4.  **/
  5.  
  6. //global variables
  7. int tempNum; //holds number as it's read
  8. int numPrime; //increment by 1 each time a prime is found
  9.  
  10. //loop to read in numbers until end of file is reached
  11. while(file.hasNext()){
  12.  
  13.    //read in number (integer in this example) and store in variable temporarily
  14.    tempNum = file.nextInt();
  15.  
  16.    //conditional statement (if statement) to check for prime numbers
  17.    if(tempNum % 2 == 0){
  18.       //number is prime, since the number divided by 2 does not produce a remainder
  19.       //so we will increment the "numPrime" variable by 1
  20.       numPrime++;
  21.    }
  22. }
Add Comment
Please, Sign In to add comment