Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Java » Programs » Factors of any number

Java program to find factors of any number

public class Main {

	public static void main(String[] args) {
		// Factors of  6 : 1,2,3,6
		// Factors of 10 : 1,2,5,10 
		
		int num = 45;
		System.out.println("Factors of " + num + " : ");
		for(int i=1; i<=num; i++) {
			if(num % i == 0) {
				System.out.println(i + " ");
		    } 
	    }
	}
}