Wap to enter some elements in an array. Replace all the Composite,niven,prime,armstrong,automorphic,kaprekar,magic,happy etc numbers by 0. Print the modified array.

 HERE WE HAVE SOLVED AS PER AS PRIME LOGIC

FOR OTHER NUMBERS FOLLOW THE NUMBER FINDING LOGIC 

FROM HERE - https://javaeasycodings.blogspot.com/p/programs-number-findings-basics.html

BUT THE LOGIC MUST BE SAME

import java.util.*;

class REPLACE_BY_ZERO

 void main()

  {

 Scanner sc=new Scanner(System.in);

 int a[]=new int[10],i,j,c;

 System.out.println("Enter 10 numbers:");

 for(i=0;i<10;i++)

 a[i]=sc.nextInt();


 for(i=0;i<10;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:");

 for(i=0;i<10;i++)

 {

 System.out.print(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