WAP to accept a no and print it
of factors in Java program
Answers
Answered by
0
Answer:
The for loop is iterated until i <= number is false. In each iteration, whether number is exactly divisible by i is checked (condition for i to be the factor of number) and the value of i is incremented by 1.
Answered by
2
- Write a program in Java to accept a num and print the factors of it.
Here is the code,
import java.util.*;
class Factors
{
public static void main(String s[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n=sc.nextInt();
System.out.print("Factors are ");
for(int i=1;i<=n;i++)
{
if(n%i==0)
System.out.print(i+"\t");
}
}// end of main
}// end of class.
Similar questions