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