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|