Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » FundamentalRSS Feeds

Even number ,Prime no. ,Factorial of a number

Posted By: Falak Khan     Category: Java     Views: 20543

Code for Even number ,Prime no. ,Factorial of a number in Java

publicclass myclass {
    public  boolean isEven(int num){
        boolean iseven;
        if(num%2==0)
            iseven=true;
        else
            iseven=false;
        return iseven;
    }
    public  boolean isPrime(int num){
        boolean p=true;
        if(num==2||num==3||num==1)
           p=true; 
        elsefor(int i=2;i<num;i++)
              {
                if(num%i==0){
                    p=false;
                    break;
                }
              }
       return p; 
    }
    publicstaticint fact(int num){
        int facto=1;
        for(int i=num;i>=1;i--){
            facto=facto*i;
        }
        return facto;
    }
    
}
  
Share: 

 
 

Didn't find what you were looking for? Find more on Even number ,Prime no. ,Factorial of a number Or get search suggestion and latest updates.

Falak Khan
Falak Khan author of Even number ,Prime no. ,Factorial of a number is from Pakistan.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Manish Kumar from United States Comment on: Nov 06
in core java the types of variables declaration is int and INTEGER. what is the difference between int and INTEGER.

Manish Kumar from United States Comment on: Nov 06
what is the difference between int and INTEGER.

View All Comments