Computer Science, asked by rayyanmohammed340, 1 day ago

Write a Java Program to display all the factors/ divisors of the number n.


Answers

Answered by r27272278
3

public class Main {

public static void main(String[] args) {

// positive number

int number = 60;

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

// loop runs from 1 to 60

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

// if number is divided by i

// i is the factor

if (number % i == 0) {

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

}

}

}

}

Output :

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

Similar questions