Computer Science, asked by ifrahkhan606, 7 months ago

write a program to create a single dimensions array of n integer print only those integer from the array which are prime numbers ​

Answers

Answered by zacknight47
5

Answer:

Prime number is the number that is only divisible by 1 and the number itself. If the number leaves remainder 0 when divided by numbers other than 1 and the number itself then, the number is not said to be a prime number. To print the prime numbers from an array, user has to declare the size of the array size and enter the elements of the array. Prime numbers are identified using iterations with the help of for loop and condition for prime number is specified using if statement. Then the numbers that satisfy the condition i.e, prime numbers are displayed on the screen as output.

Explanation:

import java.util.Scanner;

public class PrimeNumbers{

public static void main (String[] args){

int[] array = new int [5];

Scanner in = new Scanner (System.in);

System.out.println("Enter the elements of the array: ");

for(int i=0; i<5; i++)

{

array[i] = in.nextInt();

}

Similar questions