Computer Science, asked by sumi1695, 10 months ago

WAP to accept a no and print it
of factors in Java program

Answers

Answered by hasnain45
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 anindyaadhikari13
2

\star\:\:\:\sf\large\underline\blue{Question:-}

  • Write a program in Java to accept a num and print the factors of it.

\star\:\:\:\sf\large\underline\blue{Code:-}

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