Skip to content

Instantly share code, notes, and snippets.

@WakkyFree
Created February 13, 2016 03:46
Show Gist options
  • Save WakkyFree/b480d0f00e1f70bf9982 to your computer and use it in GitHub Desktop.
Save WakkyFree/b480d0f00e1f70bf9982 to your computer and use it in GitHub Desktop.
This code detects and prints prime numbers of "int number" (Answer of edX UC3Mx: IT.1.1x Introduction to Programming with Java EXAM2)
class CheckPrimeFactors {
public static void main(String args[]) {
int number = 78818740;
int count = 0;
for (int factor = 2; factor <= number; factor++){
while (number % factor == 0){
number = number / factor;
count++;
if (count == 1){
System.out.print(factor + " ");
}
}
count = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment