Find Factors of a number Java

PROGRAM TO FIND FACTORS OF A NUMBER


public class Main {

    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 + " ");
            }
        }
    }
}


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

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java