34 lines
		
	
	
	
		
			930 B
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
	
		
			930 B
		
	
	
	
		
			Java
		
	
	
	
	
	
| import java.util.Scanner;
 | |
| 
 | |
| class PrimeArray {
 | |
| 
 | |
|     public static void main(String[] args) {
 | |
|         Scanner sc = new Scanner(System.in);
 | |
|         System.out.print("Enter the size of the array: ");
 | |
|         int size = sc.nextInt();
 | |
| 
 | |
|         int[] arr = new int[size];
 | |
|         System.out.println("Enter " + size + " integers:");
 | |
|         for (int i = 0; i < size; i++) {
 | |
|             arr[i] = sc.nextInt();
 | |
|         }
 | |
| 
 | |
|         System.out.print("Prime numbers in the array: ");
 | |
|         for (int num : arr) {
 | |
|             if (num > 1) {
 | |
|                 boolean isPrime = true;
 | |
|                 for (int j = 2; j <= Math.sqrt(num); j++) {
 | |
|                     if (num % j == 0) {
 | |
|                         isPrime = false;
 | |
|                         break;
 | |
|                     }
 | |
|                 }
 | |
|                 if (isPrime) {
 | |
|                     System.out.print(num + " ");
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         sc.close();
 | |
|     }
 | |
| }
 | 
