Java Online Compiler
Example: Java Program to Find Factors of a Number using For loop
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Java Program to Find Factors of a Number using For loop import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x, i; System.out.println("-----Enter the positive integer number-----"); x = in.nextInt(); System.out.print("\nThe factors of the " + x + " are: "); for (i = 1; i <= x; ++i) { if (x % i == 0) { System.out.print(i + " "); } ++i; } System.out.print("\n"); } }
75
Output
Clear
ADVERTISEMENTS