JAVA

PART -A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7

PART-B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

/*Write a java program to create a package Number which contains a class with three static methods prime, fibanocii and Armstrong that checks whether the passed value is belongs to the corresponding types.*/

 
  
 
  PB4Package.java
   step 1: Create Subfolder pack
   step 2: Create File PB4Package.java
   
   
   
   file structure :
   Folder    : /ProgramB4.java
  sub Folder : /pack/PB$Package.java      
   
   
   /////////////////////////////////////
   
   
package pack;  
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

 

    public class PB4Package{  


        static void checkprime(int number){
   
                boolean flag = false;
            for (int i = 2; i < = number / 2; ++i) {
               
              if (number % i == 0) {
                flag = true;
                break;
              }
            }

            if (!flag)
              System.out.println(number + " is a prime number.");
            else
              System.out.println(number + " is not a prime number.");
         }





         static  void checkfibonacii(int number){
         int firstTerm = 0;
		
		int secondTerm = 1;
		
		int thirdTerm = 0;
		
		while (thirdTerm < number)
		{
			thirdTerm = firstTerm + secondTerm;
			
			firstTerm = secondTerm;
			
			secondTerm = thirdTerm;
		}
		
		if(thirdTerm == number)
		{
			System.out.println("Number belongs to Fibonacci series: "+number);
		}
		else
		{
			System.out.println("Number doesn't belongs to Fibonacci series:"+number);
		}


        }




          static void checkArmstrong(int number){

                int   originalNumber, remainder, result = 0;

                originalNumber = number;

                while (originalNumber != 0)
                {
                    remainder = originalNumber % 10;
                    result += Math.pow(remainder, 3);
                    originalNumber /= 10;
                }

                if(result == number)
                    System.out.println(number + " is an Armstrong number.");
                else
                    System.out.println(number + " is not an Armstrong number.");
             }

        }   



 

  


 
  
 // NOTE : this file must be outside  "pack" folder
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import pack.PB4Package.* ;


    public class ProgramB4{   

        public static void main(String args[])
           {

            int numder,ch=0;
	         try{

            BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter Value : ");
       
            numder = Integer.parseInt(reader.readLine());
    
            while(ch!=4){
            System.out.println("Enter 1.check Prime   2.check Armstrong 3.check fibanocii  4.exit : ");
       
            ch = Integer.parseInt(reader.readLine());
            switch(ch){

                    case 1:
                              
                              PB4Package. checkprime(numder);
                        break;

                    case 2:
                            
                        PB4Package. checkArmstrong(numder);

                    break;
                
                    case 3: 
                      PB4Package.  checkfibonacii(numder);
                    break;
                
                    case 4:
                        ch=4;

                    break;

    
                   }
    
                 }

             }catch(Exception e){
                }
          }
        
       

       
        }