Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

determine if a number is factorial in Java

// Java implementation for the above approach
class GFG
{
 
    // Function to check if the given number
    // is a factorial of any number
    static boolean isFactorial(int n)
    {
        for (int i = 1;; i++)
        {
            if (n % i == 0)
            {
                n /= i;
            }
            else
            {
                break;
            }
        }
     
        if (n == 1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
     
    // Driver Code
    public static void main (String[] args)
    {
        int n = 24;
        boolean ans = isFactorial(n);
         
        if (ans == true)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }
}
 
// This code is contributed by AnkitRai01
Comment

PREVIOUS NEXT
Code Example
Java :: selenium java control + enter 
Java :: Traversing through java map foreach 
Java :: java break string at comma 
Java :: Java telegram bot dependency 
Java :: java check if string appears twice in arraylist 
Java :: what is the max size of array in java 
Java :: get distinct values from list of objects java 
Java :: java dictionary initialization 
Java :: the import junit cannot be resolved maven 
Java :: multithreading in java 
Java :: java 14 switch 
Java :: como apanhar caracter de uma string em java 
Java :: arrays vs collections 
Java :: creating an object in java 
Java :: java log4j example 
Java :: Java Singleton Class Syntax 
Java :: java create a string 
Java :: GridLayout 
Java :: how do you handle exceptions in java 
Java :: try catch block 
Java :: java returns null 
Java :: inorder traversal 
Java :: lopping rows rethinkdb 
Java :: int to integer array in java 
Java :: Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (execution: default-compile, phase: compile) 
Java :: java listfiles filter 
Java :: square oot of 154 
Java :: java.lang.NullPointerException: Cannot store to double array because is null 
Java :: int in double umwandeln java 
Java :: sysout is not working in eclipse 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =