Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 8, 2019 09:52
Show Gist options
  • Save 0ryant/661c7eab409b3833b59a9a6b2b9feff2 to your computer and use it in GitHub Desktop.
Save 0ryant/661c7eab409b3833b59a9a6b2b9feff2 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Print All Factors of an Integer
public static void printFactors(int number){
if (number <1){
System.out.println("Invalid Value");
}
String factors="";
for (int i = 1;i<=number;i++){
if(number%i==0){
factors+=i+" ";
}
}
System.out.println(factors);
}
@KUMARGAURAV20BCA1103
Copy link

import java.util.Scanner;
public class Solution {

public static void main(String[] args) {
    // Write your code here
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int i=2;
    while(n>i)
    {
        if(n%i==0)
        {

          System.out.println(i+" ");
        }
        i++;
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment