Created
February 13, 2016 03:46
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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