Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

Wap in array to store 50 numbers and to display prime numbers in an array

0 votes
asked by anonymous

1 Answer

0 votes
import java.util.Scanner;
public class primetest {
    public static void main(String args[]){
        Scanner scanner=new Scanner(System.in);
        int prime[]=new int[50];
        System.out.println("Enter numbers");
        for(int i=0;i<prime.length;i++){
            prime[i]=scanner.nextInt();
        }
        int c=0;
        for(int i=0;i<prime.length;i++){
            for(int j=1;j<prime[i];j++) {
                if ((prime[i] % j) == 0) {
                    c=c+1;
                }
            }
            if(c==1)
                System.out.println(prime[i]);
            c=0;
            }
        }
    }
answered by Soumil Thakurata (5 points)
...