Computer Science, asked by aryankrjha18, 5 months ago

java program to enter 10 nos. and print only composite nos. among them​

Answers

Answered by keyboardavro
2

Answer:

Explanation:

mate follow the process

import java.util.Scanner;  

class example  

{  

public static void main(String args[])  

{  

 Scanner in=new Scanner(System.in);  

 System.out.print("Enter any number : ");  

 int number=in.nextInt();  

 int i=1,count=0;  

 while(i<=number)  

 {  

  if(number%i==0)  

  {  

   count++;  

  }  

  i++;  

 }  

 if(count>2)  

 {  

  System.out.println(number+" is composite number ");  

 }  

 else  

 {  

  System.out.println(number+" is not composite number");  

 }  

}  

}

Answered by anindyaadhikari13
1

Question:-

Write a java program to enter 10 numbers and print composite numbers among them.

Program:-

import java.util.*;

class Number

{

int c=0;

static boolean isComposite(int n)

{

for(int i=1;i<=n;i++)

{

if(n%i==0)

c++;

}

return (c>2);

}

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

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

int a[]=new int[10];

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

a[i]=sc.nextInt();

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

{

if(isComposite(a[i]))

System.out.println(a[i]+" is composite. ");

}

}

Similar questions