Tuesday, November 16, 2010

Factors

import java.io.*;
class Factors
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader reader=new InputStreamReader(System.in);
        BufferedReader input=new BufferedReader(reader);
        System.out.println("PLEASE INPUT THE NUMBER");
        int n=Integer.parseInt(input.readLine());
        int i=1;
        System.out.print("THE FACTORS OF "+n+" ARE :");
        while(i<=n)
        {
            if(n%i==0)
            {
                if(n!=i)
                System.out.print(i+",");
                else
                 System.out.print(i);
            }
            i++;
        }
    }
}
  1. Download Class File
  2. Download Source Code

No comments:

Post a Comment