Tuesday, 5 November 2013

SAMPLE PROGRAM OF STRING

public class string {
    // Demonstrating Strings.
public static void main(String args[]) {
String strOb1 = "First String";
String strOb2 = "Second String";
String strOb3 = strOb1 + " and " + strOb2;
System.out.println(strOb1);
System.out.println(strOb2);
System.out.println(strOb3);
}
}

OPERATOR

public class bool{
    public static void main(String []args){
    int a=10;
    int b=15;
    int c=20;
    int d=20;
    System.out.println("the value of a is " +a);
    System.out.println("the value of b is " +b);
    System.out.println("the value of c is " +c);
    System.out.println("the value of d is " +d);
    System.out.println("the evaluated expression (a>b)  is  " +(a>b));
    System.out.println("the evaluated expression (a>c)  is  " +(a>c));
    System.out.println("the evaluated expression (c>c)  is  " +(c>c));
    System.out.println("the evaluated expression (c>d)  is  " +(c>d));
    System.out.println("the evaluated expression (5>6)  is  " +(5>6));
    System.out.println("the evaluated expression (6>5)  is  " +(6>5));
    }
   
}

A SIMPLE CLASS PROGRAM FOR FINDING THE VOLUME OF A CUBOID

class cuboid
{
int length;
int breadth;
int height;
}
public class classes {
    public static void main(String []args){
        cuboid cube1=new cuboid();
        cuboid cube2=new cuboid();
        int volume1,volume2;
        cube1.length=2;
        cube1.breadth=3;
        cube1.height=4;
        cube2.length=5;
        cube2.breadth=6;
        cube2.height=7;
        volume1=cube1.length*cube1.breadth*cube1.height;
        volume2=cube2.length*cube2.breadth*cube2.height;
        System.out.println("the valume of cube one is = "+volume1);
        System.out.println("the volume of cube two is = "+volume2);
    }
   
}

PROGRAM TO FIND GREATEST OF THREE INTEGERS

import java.io.*;
public class ternary {
    public static void main(String []args){
        try{
    int a,b,c,d;
    System.out.println("ENTER THE VALUE OF a ");
    BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
    a=Integer.valueOf(obj.readLine());
    System.out.println("ENTER THE VALUE OF b ");
    b=Integer.valueOf(obj.readLine());
    System.out.println("ENTER THE VALUE OF c ");
    c=Integer.valueOf(obj.readLine());
    d=(a>b)&(a>c)?a:((b>c)&(b>a))?b:c;
    System.out.println("THE GREATEST ENTERED INTEGER IS "+d);
        }catch(IOException ex){
            System.out.println("THERE IS A EXCEPTION");
        }
    }
}

PROGRAM TO PRINT THE TABLE OF THE ENTERED NUMBER

import java.io.*;
public class table {
    public static void main(String []args){
        try{
        int a,i;
        System.out.println("ENTER THE NUMBER WHOSE TABLE IS TO BE PRINTED");
        BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
        a=Integer.valueOf(obj.readLine());
        for(i=1;i<11;i++)
        {
            System.out.println(a+"*"+i+"="+(a*i));
        }
        }catch (IOException ex){
            System.out.println("THERE IS A EXCEPTION");
        }
    }
   
}

EVEN ODD

import java.io.*;
public class evenodd {
    public static void main(String []s){
        try{
        int a;
        System.out.println("ENTER THE NUMBER ");
        BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
                a=Integer.valueOf(obj.readLine());
                if(a%2==0)
                    System.out.println("THE ENTERED NUMBER IS EVEN");
                else
                    System.out.println("THE ENTERED NUMBER IS ODD");
        }catch (IOException ex) {
         System.out.println("THERE IS A EXCEPTION");
      }
    }
   
}

PROGRAM TO PRINT HELLO WORLD !!

public class helloworld {
    public static void main(String []args){
        System.out.println("Hello world !!");
    }
}