Get Answers to all your Questions

header-bg qa

Write a program in Java to store 20 numbers in a single dimensional array .....display the numbers which are prime...?

Answers (1)

best_answer

import java.util.Scanner;

public class Main

public static void main (String[] args)

   int[] array = new int [25];

   Scanner in = new Scanner (System.in);

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

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

   

       array[i] = in.nextInt();

   

   for(int i=0; i<array.length; i++)

       boolean isPrime = true;

       for (int j=2; j<i; j++)

           if(i%j==0)

               isPrime = false;

               break;

           

       

       if(isPrime)

           System.out.println(i + " are the prime numbers in the array ");

   

Posted by

Deependra Verma

View full answer