Java Online Compiler
Example: Java Program to Find Factors of a Number using Functions
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Java Program to Find Factors of a Number using Functions import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("-----Enter the positive integer number-----"); int x = in.nextInt(); FindFactors(x); } // This function will return the factors of input number public static void FindFactors(int x) { int i = 1; 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"); } }
90
Output
Clear
ADVERTISEMENTS