Java program to show factor of a user input


Program
import java.util.*; public class ShowFactor { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("Enter a number to show the factor of it"); int num = s.nextInt(); System.out.print("Factors of " + num + " are: "); for (int i = 1; i <= num; ++i) { if (num % i == 0) { System.out.print(i + ", "); } } } }
Input
Output