Thursday, November 13, 2014

Temperature Conversion



import java.io.* ;
public class Temperature
{
      public static void fahToCelsius(double tempF)
      { 
      double tempC = (tempF - 32)/1.8 ;
      System.out.println("Temperature in Celsius is" + tempC) ;
      }
      public static void celToFahrenheit(double tempC 
      {
        double tempF = (tempC * 1.8) + 32 ;
 System.out.println("Temperature in Fahrenheit is" + tempF) ;
      }
 public static void main(String[ ] args)
      { System.out.println("1. Fahrenheit to Calcius") ;
 System.out.println("2. Celcius to Fahrenheit") ;
 System.out.println("Enter you choice") ;
 int ch = 0 ;
 DataInputStream in = new DataInputStream(System.in) ;
 double tmp ;
 System.out.println("Enter temperature to be converted") ;
      {
        if (ch == 1)
  fahToCelsius(tmp);
 else
  celToFahrenheit(tmp;
     }
}

Monday, November 10, 2014

Area of Circle



public class Circle 
{
    public static void main(double radius)
 {
  double area ;
  area = 22/7 * (radius * radius);
  System.out.println("Area of circle is " + area);
 }
}
Example of Function Overloading



class Overload
{
    void compare( int a, int b)
    {
        if (a >b)
            System.out.println(a);
        else if (b > a)
            System.out.println(b);
    }  
    void compare(char ch1, char ch2) 
    {
        if ( (int) ch1 > (int)ch2) 
            System.out.println(ch1);
        else
            System.out.println(ch2);
    }    
    void compare( String s1, String s2) 
    {
        if( s1.length() >s2.length()  )
            System.out.println(s1);
        else
            System.out.println(s2);
    }
}

Friday, November 7, 2014

Volume of various solids



  
 
 
 
 
 
 
 
 













class Volume
{
   double VOLUMEofCUBE (double side)
   {
       return side*side*side;
   }
   double VOLUMEofSPHERE (double radius)
   {
       return 4.0/3*22/7*radius*radius*radius;
   }
   double VOLUMEofCUBOID(double l, double b, double h)
   {
       return l*b*h;
   }
   double VOLUMEofCYLINDER(double radius, double height)
   {
       return 22/7*radius*radius*height;
   }
   double VOLUMEofCONE(double radius, double height)
   {
      return 1/3*22/7*radius*radius*height;
   }
}

Thursday, November 6, 2014

To check that the given number is EVEN or ODD



class EVENorODD
{  
   public void main(int n) //accepts an integer named n  
   {
      if(n % 2 == 0)
      System.out.println("You entered an even number."); 
      else    
      System.out.println("You entered an odd number."); 
   }
}

Maximum of 2 numbers



class MaxOf2Num
{
  public void main(String args[ ])
  {
     int Num1 =7, Num2 = 3, result;
     if(Num1 > Num2)
     result=Num1;
     else
     result=Num2;
     System.out.println(result);
  }
}

Minimum of 2 numbers



class MinOf2Num
{
  public void main(String args[ ])
   {
      int Num1 =7, Num2 = 3, result;
      if(Num1 < Num2)
      result=Num1;
      else
      result=Num2;
      System.out.println(result);
   }
}

Tuesday, November 4, 2014

Operators of JAVA  



public class TwoNumOps
{ 
  public static void main ( String args[ ] ) 
  {
    double x = 5.0 ;
    double y = 3.0 ;
    System.out.println ("x + y = " + ( x + y ) );
    System.out.println ("x - y = " + ( x - y ) );         
    System.out.println ("x * y = " + ( x * y ) );
    System.out.println ("x / y = " + ( x / y ) );
    System.out.println ("x % y = " + ( x % y ) );//To obtain re--mainder.
  } 
}

Monday, November 3, 2014

Basic Calculation in JAVA



class BasicCalculationInJava
{
  public void ExampleTest()
  {
  long hoursWorked =50;
  double payRate=40.0, taxRate =0.10;
  System.out.println("Hours Worked :" + hoursWorked);
  System.out.println("Payment Amount:"+(hoursWorked*payRate));
  System.out.println("Tax Payable:"+(hoursWorked*payRate*taxRate)); 
  }
}

Program:- Variable Scope

class Scope
{
    public void ScopeTest()
    {
      int x;            // known to all code withing this function
      x=10;
      if (x==10)
      {                  //start new scope
          int y = 20 ;   //known only to this block
          x = y * 2 ;
      }
      y=100;             //Error!! y not known here

      //x is still known here. 
      System.out.println("x is " + x); // No problem here

  //Hence the complier complains if I refernce a variable out of scope
}
}


Program:- Dynamic Initialization




class DynInit
{
 public void DynInitTest()
 {
  double a = 3.0,b=4.0;
  double c= Math.sqrt(a*a + b*b);
  System.out.println("Hypotenuse is "+c);
 }
}
Basic Java Program:- Just to print.




class HelloWorld
{
    public void sayHello()
    {
        System.out.println("Hello World!!");//This is  printing statement
    }
    public void display()//This is a method
    {
        System.out.println("Hi! JAVA is very easy to work with.");
    }
}