Wednesday, January 16, 2008

Find the number with Highest number of Factors in a Array

Simple Prog

import java.io.*;
class NoFactor
{
public static void main(String args[])throws IOException
{
int x[]=new int[10];
int max=0,a=0,c=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 10 integers");
for(int i=0;i<10;i++)
{
c=0;
x[i]=Integer.parseInt(br.readLine());
for(int j=1;j<=x[i];j++)
{
if(x[i]%j==0)
c++;
}
if(c>max)
{
a=x[i];
}
}
System.out.println("The number with highest number of factor = " + a +"with"+c+"factors");
}
}

No comments: