Advertisement
Guest User

CoDeNAuFgAbE

a guest
Nov 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package pr1.uebung05;
  2. import java.util.Scanner;
  3.  
  4. public class Hhhhh {
  5.  
  6. static int[] generate(int n) {
  7. int[] arr = new int[n+1];
  8. for(int x = 0; x <= n; x ++) {
  9. int number = (int) (Math.random()* 999)+1;
  10. arr[x] = number;
  11. }
  12. return arr;
  13. }
  14.  
  15.  
  16. //pruefung ob zahl an stelle n eine primzahl ist
  17. static boolean isPrim(int[] arrayStelle, int n) {
  18. for(int x = 2; x < arrayStelle[n]; x++) {
  19. if(arrayStelle[n] % x == 0) {
  20. n++;
  21. return false;
  22. }
  23. }
  24. return true;
  25. }
  26.  
  27. //prüft isPrim, generate()[] stelle
  28. static int[] filterPrim(boolean t, final int[] generatedArray) {
  29. int n = 0;
  30. int[] filteredPrim = new int[n];
  31. for(int i = 0; i <= generatedArray.length; i++) {
  32. if (t) {
  33. filteredPrim[n] = generatedArray[i];
  34. n++;
  35.  
  36. }
  37. }
  38. return filteredPrim;
  39. }
  40.  
  41.  
  42. public static void main(String[] args) {
  43.  
  44. System.out.print("Gebe eine Zahl ein: ");
  45. Scanner sc = new Scanner(System.in);
  46. int numberCount = sc.nextInt();
  47.  
  48.  
  49. System.out.print(filterPrim(isPrim(generate(numberCount),0),generate(numberCount))[0]);
  50.  
  51.  
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement