Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public static int[] returnPrime(int max) //doesn't work
  2. {
  3. int tally = 0;
  4. boolean notPrime= false;
  5. for(int i = 1; i<max; i++) {
  6. for(int j = 1; j<max; j++) {
  7. if(i%j != 0) {
  8. notPrime = true;
  9. }
  10. }
  11. if(notPrime = false) {
  12. tally++;
  13. }
  14. }
  15. int[] a = new int[tally];
  16. for(int i = 1; i<max; i++) {
  17. for(int j = 1; j<max; j++) {
  18. if(i%j != 0) {
  19. notPrime = true;
  20. }
  21. }
  22. if(notPrime = false) {
  23. a[tally-1]=i;
  24. tally--;
  25. }
  26. }
  27. return a;
  28. }
  29.  
  30.  
  31.  
  32. public static main (String[] args){
  33. int[] prime = returnPrime(10000);
  34. for(int i = 0; i<prime.length;i++) {
  35. System.out.println(prime[i]);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement