Created
October 4, 2016 19:25
-
-
Save debaimade/1be73d485b3e180e11be88d3d6f1650b to your computer and use it in GitHub Desktop.
Returns the number from which a factorial was evaluated
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
import java.util.Scanner; | |
public class ReverseFactorial { | |
public static void main(String[] args) { | |
// TODO code application logic here | |
Scanner sc = new Scanner(System.in); | |
int number = sc.nextInt(); | |
int check = number; | |
int result = 2; | |
boolean isFactorial = false; | |
while (check >= 1) { | |
if (check % result == 0) { | |
check = check / result; | |
if (check == 1) { | |
isFactorial = true; | |
break; | |
} | |
} else { | |
isFactorial = false; | |
break; | |
} | |
result++; | |
} | |
if (isFactorial) { | |
System.out.println(number + " " + result + "!"); | |
} else { | |
System.out.println(number + " NONE"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment