Monday, September 14, 2015

Generate Fibonacci Series

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cb_pr150;
import java.util.Scanner;
/**
 * Fibonacci Series Generate
 * @author Arif
 **/

public class Cb_pr150 {
    /**
     * @param args the command line arguments
     **/

    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Enter the maximum no. of terms");
        Scanner ob=new Scanner(System.in);
        int ch=ob.nextInt();
        System.out.println("Fibonacci series: ");
        int a,b,sum,n;
        a=0;
        b=1;
        System.out.print(a + ", ");
        System.out.print(b + ", ");
        for(n=1;n<=ch;n++)
        {
            sum=a+b;
            System.out.print("Term-"+n+": "+sum + ", ");
            a=b;
            b=sum;
           
        }
    }
   
}

Data Type with Arithmetic Operator in Java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jv.arith;
/**
 * Arithmetic identification in java
 * @author sm rabbi
 */

public class JvArith {
   //Demonstrate the basic arithmetic operators
    public static void main(String[] args) {
                // arithmetic usings integers
                System.out.println("Integer Arithmetic");
                int a=1+1;
                int b=a*3;
                int c=b/4;
                int d=c-a;
                int e=-a;
                System.out.println("a= "+a);
                System.out.println("b="+b);
                System.out.println("c="+c);
                System.out.println("d="+d);
                System.out.println("e="+e);
                //arithmatic using doubles
                System.out.println("\nFloatig Piont Arithmetic");
                double m=1+1;
                double n=m*3;
                double o=n/4;
                double p=o-m;
                double q=-p;
                System.out.println("m="+m);
                System.out.println("n="+n);
                System.out.println("o="+o);
                System.out.println("p="+p);
                System.out.println("q="+q);
    }
}

Generate Prime Numbers list between 1 and 100

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jv.prim;
/**
 * Generate Prime between 1 and 100
 * @author sm rabbi
 */

public class JvPrim {
    /**
     * @param args the command line arguments
     **/

    public static void main(String[] args) {
       
        int a,b,c;
        for(a=1;a<=100;a++)
        {
            c=1;
            for(b=2;b<=a/2;b++)
            {
                if(a%b == 0)
                {
                    c=0;
                    //System.out.println("not prime "+ a + " " + b + " " +a%b);
                    break;
                }
            }
           
            if(c==1)
            {
                System.out.println("prime= " +a);
            }
        }
    }
}