Write a program to input 10 numbers into an integer array and replace all prime numbers in it (if any) by 0 and print the modified array.

 


import java.util.*;
class odd
{
    void main()
    {
    Scanner ob=new Scanner(System.in);
    int a[]=new int [5];
    int i,c,j;
    System.out.println("Enter 5 nos");
    for(i=0;i<5;i++)
    {
        a[i]=ob.nextInt();
    }
    for(i=0;i<5;i++)
    {
        c=0;
        for(j=1;j<=a[i];j++)
        {
            if(a[i]%j==0)
            c++;
        }
        if(c==2)
        a[i]=0;
        
    }
    System.out.println("Modified array is");
    for(i=0;i<5;i++)
    System.out.println(a[i]);
}
}

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

It looks like you're using an ad blocker. We rely on ads to keep our site free, please whitelist us!

Click here to continue

Please whitelist our site to continue enjoying our content.

Whitelist | Close