Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pr1.uebung05;
- import java.util.Scanner;
- public class Hhhhh {
- static int[] generate(int n) {
- int[] arr = new int[n+1];
- for(int x = 0; x <= n; x ++) {
- int number = (int) (Math.random()* 999)+1;
- arr[x] = number;
- }
- return arr;
- }
- //pruefung ob zahl an stelle n eine primzahl ist
- static boolean isPrim(int[] arrayStelle, int n) {
- for(int x = 2; x < arrayStelle[n]; x++) {
- if(arrayStelle[n] % x == 0) {
- n++;
- return false;
- }
- }
- return true;
- }
- //prüft isPrim, generate()[] stelle
- static int[] filterPrim(boolean t, final int[] generatedArray) {
- int n = 0;
- int[] filteredPrim = new int[n];
- for(int i = 0; i <= generatedArray.length; i++) {
- if (t) {
- filteredPrim[n] = generatedArray[i];
- n++;
- }
- }
- return filteredPrim;
- }
- public static void main(String[] args) {
- System.out.print("Gebe eine Zahl ein: ");
- Scanner sc = new Scanner(System.in);
- int numberCount = sc.nextInt();
- System.out.print(filterPrim(isPrim(generate(numberCount),0),generate(numberCount))[0]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement