Question 67 : Write a program in Java to print all the factors of a number.
Java Program :
import java.io.*;
class factors
{
static void main()throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
int a,i;
System.out.print("Enter the number : ");
a=Integer.parseInt(buf.readLine());
System.out.print("\n");
System.out.print("The factors are : ");
for(i=1;i<=a/2;i++)
{
if(a%i==0)
System.out.print(i+",");
}
System.out.print(a);
}
}
Java Program :
import java.io.*;
class factors
{
static void main()throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
int a,i;
System.out.print("Enter the number : ");
a=Integer.parseInt(buf.readLine());
System.out.print("\n");
System.out.print("The factors are : ");
for(i=1;i<=a/2;i++)
{
if(a%i==0)
System.out.print(i+",");
}
System.out.print(a);
}
}
can u pls write it using import java.util.*;
ReplyDeletepls i need it