Java Blog

 
 
 
 */
package filespaths;
import java.nio.file.*;
//import java.nio.file.Paths;
import java.io.*;


import java.util.*;
/**
 *
 * @author Hira
 */
public class Filespaths {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {


     System.out.println(\"Enter a no\");
     Scanner in=new Scanner(System.in);
     int num=in.nextInt();
     myclass obj=new myclass();
     System.out.println(\"Enter 1 to check even/odd\");
     System.out.println(\"Enter 2 to check Prime/not Prime\");
     System.out.println(\"Enter 3 to find Factorial. \");
     System.out.println(\"Enter your choice?\");
     int n=in.nextInt();
     switch(n){
         case 1:
            boolean e=obj.isEven(num);
            if(e)
              System.out.println(num+\" is Even \");
            else
              System.out.println(num+\" is Odd \");  
            break;
         case 2:
             boolean r=obj.isPrime(num);
             if(r)
              System.out.println(num+\" is Prime \");
            else
              System.out.println(num+\" is No Prime \");
             break;
         case 3:
            int y= myclass.fact(num);
            System.out.println(y);
             break;
         default:
             System.exit(0);
     }

    }   

}
class 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; 
        else
              for(int i=2;i<num;i++)
              {
                if(num%i==0){
                    p=false;
                    break;
                }
              }
       return p; 
    }
    public static int fact(int num){
        int facto=1;
        for(int i=num;i>=1;i--){
            facto=facto*i;
        }
        return facto;
    }
}

 
 
Didn't find what you were looking for? Find more on Even no or Prime no?????