Program to calculate factorial of given number in Java

/*Program to calculate factorial of given number*/

class P2
{
    public static void main(String args[])
    {
        int i , number , factorial ;
        number = 7;

        for (i=1,factorial=1 ; i<=number ; i++)
            factorial = factorial * i ;

         System.out.println("The factorial of "+number+" : "+factorial);
    }
}
READ MORE - Program to calculate factorial of given number in Java

Program to implement Fibonacci series in Java

/* Program to implement Fibonacci series*/

class P1
{
    public static void main(String args[])
    {
        int x , y , z = 0 ;
        System.out.println("The Fibonacci Series :\n");
        System.out.println("====================\n");
        System.out.println("0\n1");

        for (x=0,y=1 ; y<1000 ; x=z)
        {
            z = y ;
            y = x + y ;
            System.out.println(y);
        }
    }
}
READ MORE - Program to implement Fibonacci series in Java

Program to display first 10 even numbers and their squares

/*Program to display first 10 even numbers and their squares*/

class P3
{
    public static void main(String args[])
    {
        int n ,count=1;
        System.out.println("First 10 even numbers and their squares:\n");
        System.out.println("\nNumber\tSquare\n");
        for (n=2 ;count<=10; n=n+2)
        {
            System.out.println(n+"\t"+(n*n));
            count++;
        }
    }
}
READ MORE - Program to display first 10 even numbers and their squares

Program to demonstrate the boolean logical operators

/* Program to demonstrate the boolean logical operators */

class BoolLogic
{
    public static void main(String args[])
    {
        boolean a = true;
        boolean b = false;
        boolean c = a|b;
        boolean d = a&b;
        boolean e = a^b;
        boolean f = (!a & b)|(a & !b);
        boolean g = !a;
        System.out.println("         a = "+a);
        System.out.println("         b = "+b);
        System.out.println("       a|b = "+c);
        System.out.println("       a&b = "+d);
        System.out.println("       a^b = "+e);
        System.out.println(" !a&b|a&!b = "+f);
        System.out.println("        !a = "+g);
    }
}
READ MORE - Program to demonstrate the boolean logical operators

/* Program to demonstrate Bitwise Shift Operators */

class BitShift
{
    public static void main(String args[])
    {
        int A = 6, B=-6;
        System.out.println("A : "+A);
        System.out.println("B : "+B);
        System.out.println("A >> 2 : "+(A>>2));
        System.out.println("A << 1 : "+(A<<1));
        System.out.println("A >>> 1 : "+(A>>>1));
        System.out.println("B >> 1 : "+(B>>1));
        System.out.println("B >>> 1 : "+(B>>>1));
    }
}
READ MORE -

Program to demonstrate Multiple statements within if

/* Program to demonstrate Multiple statements within if */

class IfDemo2
{
    public static void main(String args[])
    {   
        int marks;
        marks = 35;

        if(marks<40)
        {
            int lessmarks=40-marks;
            System.out.println("\nSorry!!!!!you are failed");
            System.out.println("\nYou should have got "+lessmarks+" more marks");

        }
    }
}
READ MORE - Program to demonstrate Multiple statements within if

program to demonstarte if statement

/* program to demonstarte if statement  */

class IfDemo1
{
    public static void main(String args[])
    {
        int no;
        no=5;
        if(no<100)
            System.out.println("The number is less than 100!!!");
    }
}
READ MORE - program to demonstarte if statement

Program to compute Permutation and Combination

Program to compute Permutation and Combination


class P4
{
    public static void main(String args[])
    {
        int i , n , r , P , C ;
        int factorial , temp , result ;

        n = 6; r=3;

                 for (i=1,factorial=1 ; i<=n ; i++)    /* Calculate n! */
            factorial = factorial * i ;

                 for (i=1,temp=1 ; i<=r ; i++)         /* Calculate r! */
            temp = temp * i ;

        for (i=1,result=1 ; i<=(n-r) ; i++)    /* Calculate (n-r)!*/
            result = result * i ;

        P = factorial / temp ;
        C = P / result ;

        System.out.println(" Permutation  : "+P);
        System.out.println(" Combination  :  "+C);
    }
}
READ MORE - Program to compute Permutation and Combination

Program to determine grade for given marks, using switch statement

/* Program to determine grade for given marks, using switch statement*/

class GradeSwitch
{
    public static void main(String args[])
    {
        int marks,index ;
        String grade;

        marks= 83;
        index = marks/10;

        switch(index)
        {
            case 10:
            case 9:
            case 8:
                grade="Honours";
                break;
            case 7:
            case 6:
                grade="First Division";
                break;
            case 5:
                grade="Second Division";
                break;
            case 4:
                grade="Third Division";
                break;
            default:
                grade="Fail";
                break;
        }
        System.out.println("Marks : "+marks+" Grade : "+grade);
    }
}
READ MORE - Program to determine grade for given marks, using switch statement

program to determine grade for given marks

/*  program to determine grade for given marks  */

class Grade
{
    public static void main(String args[])
    {
        int marks = 83;
        String grade;

        if(marks > 79)
            grade="Honours";
        else if(marks>59)
            grade="First division";
            else if(marks > 49)
                grade="Second division";
                else if(marks > 39)
                    grade="Third division";
                else
                grade="Fail";

        System.out.println("Marks : "+marks+"\t Grade : "+grade);
    }
}
READ MORE - program to determine grade for given marks

Program of finding out the Greatest Common Division (GCD) or the Highest Common Factor (HCF) of the given two numbers, using while loop

/* Program of finding out the Greatest Common Division (GCD) or the Highest Common Factor (HCF) of the given two numbers, using while loop*/

class GCD
{
    public static void main(String args[])
    {
        int num_1 , num_2 ;
        num_1 = 25;
        num_2 = 15;
       
        System.out.print("The GCD of "+num_1+" and "+num_2);

        while ((num_1!=0) && (num_2!=0))
        {        
            if (num_1 > num_2)
                num_1 = num_1 - num_2 ;
            else
                num_2 = num_2 - num_1 ;
        }

        System.out.print(" is "+num_1);
    }
}
READ MORE - Program of finding out the Greatest Common Division (GCD) or the Highest Common Factor (HCF) of the given two numbers, using while loop

program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7

/* program to find the number of and sum of all integers greater
 than 100 and less than 200 that are divisible by 7
*/

class ForDemo4
{
    public static void main(String args[])
    {
        int no,count=0,sum=0;

        for(no=101;no>100&&no<200;no++)
            if(no%7==0)
            {
                System.out.println(" "+no+" is divisible by 7");
                sum=sum+no;
                count=count+1;
            }

        System.out.println("\n Total no. of integer between 100 to 200 that are divisible by 7 : "+count);
        System.out.println(" Sum of all integer between 100 to 200 that are divisible by 7 : "+sum);
    }
}
READ MORE - program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7

Program to display table of 15

/* Program to display table of 15  */

class ForDemo2
{
    public static void main(String args[])
    {
        int i = 0 ;

        System.out.println("Table of 15 -\n");

        for (i=1 ; i<=10 ; i++)
            System.out.println("15 * "+i+" : "+(15*i));
    }
}
READ MORE - Program to display table of 15

Program to compute sum of first 20 numbers using for loop

/* Program to compute sum of first 20 numbers using for loop */

class ForDemo1
{
    public static void main(String args[])
    {
        int i , sum = 0 ;

        for (i=1 ; i<21 ; i++)
            sum = sum + i ;
        System.out.println("The sum of first twenty numbers is "+sum);
    }
}
READ MORE - Program to compute sum of first 20 numbers using for loop

Program to demonstrate Floating-point arithmetic

/* Program to demonstrate Floating-point arithmetic */

class FloatPoint
{
    public static void main(String args[ ])
    {
        float a=10.5F,b=6.1F;
        System.out.println("a = "+a);
        System.out.println("b = "+b);
        System.out.println("a + b = "+(a+b));
        System.out.println("a - b = "+(a-b));
        System.out.println("a * b = "+(a*b));
        System.out.println("a / b = "+(a/b));
      
    }
}
READ MORE - Program to demonstrate Floating-point arithmetic

Program to demonstrate casting Incompatible Types

/* Program to demonstrate casting Incompatible Types */

class Casting
{
    public static void main(String args[])
    {
        byte b;
        int i = 258;
        double d = 340.142;

        System.out.println("\n Conversion of int to byte.....");
        b = (byte) i;
        System.out.println(" integer i : "+i+" is converted to byte b : "+b);
       
        System.out.println("\n Conversion of double to int.....");
        i = (int) d;
        System.out.println(" double d : "+d+" is converted to integer i : "+i);
       
        System.out.println("\n Conversion of double to byte.....");
        b = (byte) d;
        System.out.println(" double d : "+d+" is converted to byte b : "+b);
    }
}
READ MORE - Program to demonstrate casting Incompatible Types

program to check whether number is even or odd

/* program to check whether number is even or odd */

class EvenOdd
{
    public static void main(String args[])
    {
        int no , temp ;
        no = 35;
       
        temp = no % 2 ;
        if (temp == 0)
            System.out.println("The number "+no+" is Even");
        else
            System.out.println("The number "+no+" is Odd");
    }
}
READ MORE - program to check whether number is even or odd

Program to tests whether the given number is divisible by 3 and 5, both

/* Program to tests whether the given number is divisible by 3 and 5, both */

class Divby3_5
{
    public static void main(String args[])
    {
        int no ;
        no = 15;
       
        if (no%3 == 0)
                  if (no%5 == 0)
                       System.out.println("The number "+no+" is divisible by 3 and 5");
    }
}
       
READ MORE - Program to tests whether the given number is divisible by 3 and 5, both

Program to find Factorial of number

/*  Program to find Factorial of number */

class Demo
{
    public static void main(String args[])
    {
        int fact=1;
        for(int num=5;num>=1;num--)
        {
            fact*=num;
        }
        System.out.println("Factorial of 5 is :"+fact);
    }
}
READ MORE - Program to find Factorial of number

Program to demonstrate continue statement with a label

/* Program to demonstrate continue statement with a label */

class ContinueDemo2
{
    public static void main(String args[])
    {
      OUTER:for(int i =0;i<10;i++)
        {
           for(int j =0;j<10;j++)
           {
            if(j>i)
            {
                System.out.println();
                continue OUTER;
            }
            System.out.print(" "+(i*j));
           }
         }
        System.out.println();
    }
}
READ MORE - Program to demonstrate continue statement with a label

Program to demonstrate continue statement

/* Program to demonstrate continue statement */

class ContinueDemo1
{
    public static void main(String args[])
    {
        for(int i =0;i<10;i++)
        {
            System.out.print(i+" ");
            if(i%2==0) continue;
            System.out.println("");
        }
    }
}
READ MORE - Program to demonstrate continue statement

Program to illustrate the command-line arguments

/*  Program to illustrate the command-line arguments  */

class CommandLineDemo
{
    public static void main(String args[])
    {
        for(int i =0;i<args.length;i++)
            System.out.println("args["+i+"]: "+args[i]);
    }
}
READ MORE - Program to illustrate the command-line arguments

Program to demonstrates Call by Value

/* Program to demonstrates Call by Value  */

class Sample
{ int c,d;
     
   
    void cal(int c, int d)
    {  
       
        c=c+2;
        d=d-2;
   
    }
}

class CallByValue
{
    public static void main(String args[])
    {
        Sample s=new Sample();
        int p=20,q=10;

        System.out.println(" p and q Before call :"+p+", "+q);
       
        s.cal(p,q);

        System.out.println(" p and q After call  :"+p+", "+q);
    }
}
READ MORE - Program to demonstrates Call by Value

Program to demonstrates Call by reference

/* Program to demonstrates Call by reference  */

class Sample
{
    int p,q;

    Sample(int x,int y)
    {
        p=x;
        q=y;
    }

    // Pass an Object
    void cal(Sample obj)
    {
        obj.p=obj.p+2;
        obj.q=obj.q-2;
    }
}

class CallByRef
{
    public static void main(String args[])
    {
        Sample s=new Sample(20,10);
       
        System.out.println(" p and q Before call : "+s.p+", "+s.q);
       
        s.cal(s);

        System.out.println(" p and q After call  : "+s.p+", "+s.q);
    }
}
READ MORE - Program to demonstrates Call by reference

Program that uses break as a civilized form of goto

/* Program that uses break as a civilized form of goto */

class BreakDemo3
{
    public static void main(String args[])
    {
        boolean b = true;

        FIRST: {
            SECOND : {
                THRID : {
                      System.out.println("Before break....");
                      if(b) break SECOND ; //break out of second block
                      System.out.println("This won't execute....");
                    }
                    System.out.println("This won't execute....");
                 }              
              System.out.println("This is after SECOND block....");
            }
    }
}
READ MORE - Program that uses break as a civilized form of goto

Program that uses break in nested for loop

/* Program that uses break in nested for loop  */


class BreakDemo2
{
    public static void main(String args[])
    {
        for(int i =0;i<3;i++)
        {
            System.out.print("Iteration "+i+" = ");
            for(int j =0;j<100;j++)
            {
                if(j==10) break;      //terminate loop if j is 10
                System.out.print(j+" ");
            }
            System.out.println();
        }
        System.out.println(" End of outer Loop");
    }
}
READ MORE - Program that uses break in nested for loop

Program of adding first ten numbers using the while loop

/*  Program of adding first ten numbers using the while loop */

class AddWhile
{
    public static void main(String args[])
    {
        int j = 1 , sum = 0 ;

        while (j<10)
        {
            sum = sum + j ;
            j++ ;
        }

        System.out.println("The sum of first ten numbers is : "+sum);
       
        while (j<50)
        {
            sum = sum + j ;
            j++ ;
        }

        System.out.println("The sum of first fifty numbers is : "+sum);
       
        while (j<100)
        {
            sum = sum + j ;
            j++ ;
        }

        System.out.println("The sum of first hundred numbers is : "+sum);
    }
}
READ MORE - Program of adding first ten numbers using the while loop

Program to demonstrate Access Protection

/* Program to demonstrate Access Protection */

class Demo
{
    int p;            // default access
    public int q;    // public access
    private int r;  // private access

    // methods to access r
    void setr(int i)     
    {        // set r's value
        r = i;
    }
   
    int getr()
    {      // get r's value
        System.out.println(" p, q, and r = "+r);
        return r;
    }
}


class AccessProDemo
{
    public static void main(String args[])
    {
        Demo d= new Demo();
       
        // OK : 'p' and 'q' may be accessed directly
        d.p=300;
        d.q=400;
        //d.r=252;

        // NOT OK : 'r' cannot be accessed outside the class, hence will cause an error
        // d.r=50;
        d.getr();
        // You must access 'r' through its methods
        d.setr(500);        //OK
       
        System.out.println(" After stting p, q, and r ");
        System.out.println(" p, q, and r = "+d.p+", "+d.q+" and "+d.getr());
    }
}
READ MORE - Program to demonstrate Access Protection

Program to demonstrate type promotion

/* Program to demonstrate type promotion */

class TypePromotion
{
    public static void main(String args[])
    {
        byte b = 52;
        char c = 'a';
        short s = 1024;
        int i = 50000;
        float f = 7.67f;
        double d = .1234;
        double result = (f*b) + (i/c) - (d*s);
       
        System.out.println((f*b)+" + "+(i/c)+" - "+(d*s)+" = "+result);
       
    }
}
READ MORE - Program to demonstrate type promotion

Program to demonstrate the ternary Operator


/* Program to demonstrate the ternary Operator */

class Ternary
{

         public static void main(String args[])
    {
              int value1 = 1;
              int value2 = 2;
              int result;
              boolean Condition = true;

              result = Condition ? value1 : value2;

              System.out.println("Result is : "+result);
   
         }
}
   
READ MORE - Program to demonstrate the ternary Operator

Program to calculate Remainder

/*   Program to calculate Remainder   */

class Remainder
{

    public static void main (String args[])
    {

        int i = 10;
        int j = 3;

        System.out.println("i is : " + i);
            System.out.println("j is : " + j);
 
          int k = i % j;
        System.out.println("i % j is : " + k);
     }

}
READ MORE - Program to calculate Remainder

/* Program to compute the area of a circle */

class P15
{
    public static void main(String args[])
    {
        double pi,r,a;

        r=10.8;     //radius of circle
        pi=3.1416;    //pi, approximately
        a = pi*r*r;      //compute area

        System.out.println(" Area of circle is :"+a);
    }
}
READ MORE -

Program to demonstrate Relational Operators

/* Program to demonstrate Relational Operators */

class RelationalOp
{
    public static void main(String args[])
    {
        float x = 15.0F, y = 10.65F, z = 25.0F;
        System.out.println("x = "+x);
        System.out.println("y = "+y);
        System.out.println("z = "+z);
        System.out.println("x < y is : "+(x<y));
        System.out.println("x > y is : "+(x>y));
        System.out.println("x == z is : "+(x==z));       
        System.out.println("x <= z is : "+(x<=z));
        System.out.println("x >= y is : "+(x>=y));
        System.out.println("y != z is : "+(y!=z));
        System.out.println("y == x+z is : "+(y==x+z));
    }
}
READ MORE - Program to demonstrate Relational Operators

Program to convert given temperature in Fahrenheit to Celsius

/* Program to convert given temperature in Fahrenheit to Celsius */

class P16
{
    public static void main(String args[])
    {
        double celsius1,celsius2,fahrenheit;       
        fahrenheit= 40;
        celsius1= (fahrenheit-32)/1.8;
        System.out.print(" Temperature in fahrenheit is "+fahrenheit);      
                System.out.println(" is converted to celsius :"+celsius1);
        fahrenheit= 60;
        celsius2= (fahrenheit-32)/1.8;
        System.out.print(" Temperature in fahrenheit is "+fahrenheit);      
                System.out.println(" is converted to celsius :"+celsius2);
       
    }
}
READ MORE - Program to convert given temperature in Fahrenheit to Celsius

Program to determine salvage value

/* Program to determine salvage value */

class P14
{
    public static void main(String args[])
    {
        double purchase_price, salvage_value,depreciation;
        int years_of_service;

        purchase_price = 250;
        years_of_service = 5;
        depreciation = 30;

        (salvage_value)= -(depreciation*years_of_service-purchase_price);
        System.out.println(" salvage value ="+salvage_value);

    }
}
READ MORE - Program to determine salvage value

Program to computes the length of the hypotenuse of a right triangle

/* Program to computes the length of the hypotenuse of a right triangle */

class P12
{
    public static void main(String args[])
    {
        double a = 3.0, b= 4.0;
        double c = Math.sqrt(a*a+b*b);
        System.out.println(" Hypotenuse is :"+c);
    }
}
READ MORE - Program to computes the length of the hypotenuse of a right triangle

Program to find absolute value of the variable

/* Program to find absolute value of the variable */

class P11
{
    public static void main(String args[])
    {
        int x = -25, y =-18;

        /* Using Ternary Operator */
        System.out.println("Value of x = "+x);
        x= x<0?-x:x;
        System.out.println("Absolute value of x = "+x);

        /* Using mathematical function 'abs()' */
        System.out.println("\nValue of y = "+y);
        System.out.println("Absolute value of y = "+Math.abs(y));
    }
}  
READ MORE - Program to find absolute value of the variable

Program to find minimum Number

/* Program to find minimum Number */

class P10
{    
     public static void main(String args[])
     {
            int a =3 , b = 7 , c = 0 ;
                int result;
            result = ( a < b ? a : b ) < c ? ( a < b ? a : b ) : c ;
        System.out.println(" The minimum number in "+a+", "+b+","+c+" is "+result);   
  

      }
}
READ MORE - Program to find minimum Number

Program to implements the quadratic formula

/*  Program to implements the quadratic formula */

class P9
{

    public static void main(String args[])
    {

        //implements the quadratic formula

        double a=2,b=8.001,c=8.002 ;
       
        System.out.println("a :"+a);
        System.out.println("b :"+b);
        System.out.println("c :"+c);


        System.out.println("\n The equation is : "+a+" * x * x + "+b+" * x + "+c+" = 0 ");

        double d = b * b - 4 * a * c ;
        double sqrtd = Math.sqrt(d);
        double x1 = ( - b + sqrtd) / (2 * a ) ;
        double x2 = ( - b - sqrtd) / (2 * a ) ;

        System.out.println("The Solution are  : ");
        System.out.println("\t x1 ="+x1);
        System.out.println("\t x2 ="+x2);
       
    }
}
READ MORE - Program to implements the quadratic formula

Program to exchange the digits of 2-digit number

/*  Program to exchange the digits of 2-digit number */

class P8
{
    public static void main(String args[])
    {
        int number= 71, temp, tens;

        System.out.println("\n The Original Number : "+number);

        temp = number % 10;
        tens = 10 * temp;
        temp = number /10;
        number = tens + temp ;

        System.out.println("\n The Exchanged Number : "+number);
              
    }
}
READ MORE - Program to exchange the digits of 2-digit number

Program to split of a 4 digit number

/*  Program to split of a 4 digit number */

class P7
{
    public static void main(String args[])
    {
        int x = 1234, y, z;

        y = x /1000 ;
        System.out.println(" The digit in the Thousand's place =  "+y);

        z = x % 1000;
        y = z /100;
        System.out.println("\n The digit in the Hundred's place =  "+y);

        z = z % 100;
        y = z / 10;
        System.out.println("\n The digit in the Ten's place =  "+y);

        y = z % 10;
        System.out.println("\n The digit in the Unit's place =  "+y);
              
      }
}
READ MORE - Program to split of a 4 digit number

Program to converts inches to centimeters

/*  Program to converts inches to centimeters */

class P6
{
    public static void main(String args[])
    {
        float inches = 16.9F, cm ;       
        cm = 2.54F * inches ;
        System.out.println(""+inches+" inches = "+ cm +" centimeters");
               
    }
}
READ MORE - Program to converts inches to centimeters

Program to calculate the simple interest

  /*  Program to calculate the simple interest */

class P5
{
    public static void main(String args[])
    {
        float principle, no_of_years, rate_of_interest, simple_interest;
                principle = 10000;
                no_of_years= 6;
                rate_of_interest = 8.5F;
                simple_interest = principle * no_of_years *  rate_of_interest ;
                simple_interest = simple_interest / 100 ;
        System.out.println("\n Simple Interest on a principle of "+principle+" is "+simple_interest+" at the rate of "+rate_of_interest+" for a period of "+no_of_years);

    }
}
READ MORE - Program to calculate the simple interest

Program for computing the volume of a sphere

/*  Program for computing the volume of a sphere  */

class P4
{
    public static void main(String args[])
    {
        float r=2, volume, pi =  3.14152F;
       
        volume = (4 * pi * r * r * r) / 3 ;
                System.out.println("Volume : "+volume);
    }
}
READ MORE - Program for computing the volume of a sphere

Program to interchange the value of the given 2 numbers

/* Program to interchange the value of the given 2 numbers */

class P3
{

    public static void main(String args[])
    {
        int no1=5, no2=18, temp;
       
        System.out.println("\nBefore interchange Numbers are : ");
        System.out.println("First Number : "+no1);
        System.out.println("Second Number : "+no2);

        temp = no1;
        no1 = no2;
        no2 = temp;

        System.out.println("\nAfter interchange Numbers are : ");
        System.out.println("First Number : "+no1);
        System.out.println("Second  Number : "+no2);

    }
}
READ MORE - Program to interchange the value of the given 2 numbers

Program to find Square and cube of a Number

/* Program to find Square and cube of a Number */

class P2
{    

     public static void main(String args[])
     {
    int i=5 ;
   
    System.out.println(" The Number is  : "+i) ;
    System.out.println("The Square of Number is  : "+(i*i));
    System.out.println("The Cube of Number is  : "+(i * i* i));
             
      }
}
READ MORE - Program to find Square and cube of a Number

Program to calculate average of 3 numbers

/* Program to calculate average of 3 numbers */

class P1
{
     public static void main(String args[])
     {
             int a, b, c, average;
             a = 3;
         b = 7;
             c = 2 ;
             average = ( a + b + c ) / 3;
             System.out.println(" Average : "+average);
     }
}
READ MORE - Program to calculate average of 3 numbers

Program to demonstrate Mathematical Functions

class P
{
    public static void main(String args[])
    {
        double x= Math.floor(40.6);
        double y = Math.abs(40.6);
        System.out.println(" Value of x is ="+x+" and y is ="+y);

    }
}
READ MORE - Program to demonstrate Mathematical Functions

Program to demonsrate System.arraycopy() function

/* Program to demonsrate System.arraycopy() function*/

class Arraycopy1
{
    public static void main(String[] args)
    {
            char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',
                         'i', 'n', 'a', 't', 'e', 'd' };
            char[] copyTo = new char[7];

            System.arraycopy(copyFrom, 2, copyTo, 0, 7);
            System.out.println(new String(copyTo));
        }
}
READ MORE - Program to demonsrate System.arraycopy() function

Mathematical Applications/Operators/Functions

/*  Mathematical Applications/Operators/Functions  */

import java.lang.System;
import java.lang.Math;

public class MathApp {
 public static void main(String args[]) {
  System.out.println(Math.E);
  System.out.println(Math.PI);
  System.out.println(Math.abs(-1234));
  System.out.println(Math.cos(Math.PI/4));
  System.out.println(Math.sin(Math.PI/2));
  System.out.println(Math.tan(Math.PI/4));
  System.out.println(Math.log(1));
  System.out.println(Math.exp(Math.PI));
  for(int i=0;i<5;++i)
   System.out.print(Math.random()+" ");
  System.out.println();

}

}



Output:
 /*
2.718281828459045
3.141592653589793
1234
0.7071067811865476
1.0
0.9999999999999999
0.0
23.140692632779267
0.11532581519046647 0.4458601351066609 0.980757698093553 0.23030711522893255 0.2
635402093705278
*/
READ MORE - Mathematical Applications/Operators/Functions

Program to demonstrates the increment operator

/* Program to demonstrates the increment operator*/

class IncDec
{
    public static void main(String args[])
    {
        int a = 10;
        int b = 20;
        int c,d;
        c = ++b;
        d = a++;
        c++;
        System.out.println("a     = "+a);
        System.out.println("b     = "+b);
        System.out.println("c     = "+c);
        System.out.println("d     = "+d);
    }
}
READ MORE - Program to demonstrates the increment operator

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|