Chapter: Math Class Last Updated: 12-09-2017 16:54:25 UTC

Program:

` ````
/* ............... START ............... */
public class JavaDisplayFactors {
public static void main(String[] args) {
int number = 80;
System.out.print("Factors of " + number + " are: ");
for(int i = 1; i <= number; ++i) {
if (number % i == 0) {
System.out.print(i + " ");
}
}
}
}
/* ............... END ............... */
```

Output

Factors of 80 are: 1 2 4 5 8 10 16 20 40 80

Notes:

- In this program, you'll learn to display all factors of a given number using for loop in Java.
- In this program for loop is iterated until i <= number is false.
- In each iteration, whether number is exactly divisible by i is checked to be the factor of number and the value of i is incremented by 1.

Tags

Factors Of Number, Java, Math

1 2