Computer Science, asked by amnabatoolaiman, 9 months ago

Write a program in Java to accept a number and display its factors?​

Answers

Answered by Vinay0420
4

Your answer is here dear....

Explanation:

public class Factors {

public static void main(String[] args) {

int number = 60;

System.out.print("Factors of " + number + " are: ");

for(int i = 1; i <= number; ++i) {

if (number % i == 0) {

System.out.print(i + " ");

}

}

}

}

When you run the program, the output will be:

Factors of 60 are: 1 2 3 4 5 6 10 12 15 20 30 60

In the above program, number whosefactors are to be found is stored in the variable number (60).

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.

HOPE. It's HELP YOU DEAR....

Answered by singhjuhy0
2

Answer:

input the no. using while loop

Attachments:
Similar questions