Monday, 22 September 2014

WhileDemo


public class WhileDemo {

   
    public static void main (String args[])
   
    {
       
         int counter = 1;
       
         while (counter<=108)
         {
                        
             System.out.println (counter+ " Om Namah Shivay......");
             counter= counter+1;
         }
       
    }
}

TypeWrap


public class TypeWrap {
    public static void main(String[] args)
    {
        System.out.println("Here are the variables....");
        char c  = 'x';
        byte b = 50;
        short s = 1996;
        int i  = 123456789;
        long l = 1234567654321L;
        float f1 = 3.142F;
        float f2 = 1.2e-5F;
        double d2 = 0.00000000987;
       
        System.out.println("  c =  "+c);
        System.out.println("  b =  "+b);
        System.out.println("  s =  "+s);
        System.out.println("  i =  "+i);
        System.out.println("  l =  "+l);
        System.out.println("  f1 =  "+f1);
        System.out.println("  f2=  "+f2);
        System.out.println("  d2=  "+d2);
       
        System.out.println("Type conversion");
        short s1 = (short)b; //byte to short
        short s2 = (short)i; //integer to short -- Truncated value
        float n1 = (float)l;  //long to float
        int m1 = (int)f1;     // Fraction loss
       
        System.out.println("(short)b =  "+s1);
        System.out.println("(short)i =  "+s2);
        System.out.println("(float)l =  "+n1);
        System.out.println("(int)f1  =  "+m1);
           
    }

}

Studentdetails


public class Studentdeatils {
   
    public static void main(String args[])

    {
int bio=95,chem=85,phy=80,maths=90,sum=0,regno=10;
sum=bio+chem+phy+maths;
String name="Vidisha";
float avg=sum/4;
System.out.println("**********");
System.out.println("Student name:-"+name);
System.out.println("Reg no:-"+regno);
System.out.println("Biology:-"+bio);
System.out.println("Chem:-"+chem);
System.out.println("Phy:-"+phy);
System.out.println("Maths:-"+maths);
System.out.println("Total:-"+sum);
System.out.println("Avg:-"+avg);
System.out.println("**********");
}
}

Student


public class Student {
   
    String name;
    String div;
    String schoolname;
    String subject;
   
    public void printData (Student S)
    {
       
        System.out.println("*****************************");
        System.out.println("Name:"+S.name);
        System.out.println("Div :"+S.div);
        System.out.println("School:"+S.schoolname);
        System.out.println("Subject:"+S.subject);
        System.out.println("*****************************");
    }
   
   
    public static void main (String args[])
    {
       
        Student s1 = new Student();
        s1.name = "Urvashi";
        s1.div  = "Computer";
        s1.schoolname="IIAR";
        s1.subject="COM102";
        s1.printData(s1);
       
        Student s2= new Student();
        s2.name="Akshay";
        s2.div  = "Computer";
        s2.schoolname="IIAR";
        s2.subject="COM102";
       
        s2.printData(s2);
       
       
    }
   
   
   

}

Person


public class Person {
   
   
   
    public static void main (String args[])
    {
        int a=7 ,b=8,sum=0;
        sum = a+b;
       
        System.out.println("output: " + a+b);
       
    }

}

InterestCalculator


public class InterestCalculator {

   
    double principle,intrate,noyear;
   
    public void calculateInterest(double p, double r, double n)
    {
        double interest  = (p*r*n)/100;
        System.out.println("Interest :"+interest);
   
    }
   
    public static void main(String args[])
    {
   
       
        InterestCalculator IC = new InterestCalculator();
        IC.calculateInterest(1000, 12, 1);
        IC.calculateInterest(5000, 12, 1);
        IC.calculateInterest(10000, 12, 1);
        IC.calculateInterest(15000, 12, 1);
        IC.calculateInterest(20000, 12, 1);
        IC.calculateInterest(25000, 12, 1);
       
       
    }
}

IfElseWhiledemo


public class IfElseWhiledemo {
   
    public static void main (String args[])
    {
       
        int i =1;
       
        while (i <=100)
        {
           
            if(i%2==0)
            {
                System.out.println(i);
            }
         i++;
        }
       
        System.out.println(i );
    }

}

IFElseDemo2


public class IFElseDemo2 {
   
    public static void main (String args[])
    {
       
        int a = 100 , b=50;
       
        if (a >b )
        {
            System.out.println (" A is greater than B");
           
        }
        else
        {
            System.out.println("B is greater than A");
        }
        System.out.println("Now I am out side if -else , in any case i get print");
    }
}

class3D


public class class3D {
   
    double x;
    double y;
    double z;
   
    class3D()
    {
      x = 5;
      y=5;
      z=5;
   
    }
    class3D (double px,double py )
    {
        x = px;
        y=py;
   
    }
   

}

IfElseDemo


public class IfElseDemo {
   
   
    public static void main (String args[])
   
    {
       
        String name = "Raj";
        int balance = 5000;
       
        if (name.equalsIgnoreCase("Raj"))
        {
            System.out.println("Successful login");
           
        }
        else
        {
            System.out.println("Invalid login... Account does not exist");
        }
           
       
       
       
    }
   
   
   

}

HelloWorld


public class HelloWorld {

   
    public static void main (String args[])
    {
   
       
    }
}

class3DExample


public class class3DExample {
   
    public static void main (String args[])
    {
       
        class3D obj1 = new class3D(15,10);
       
       
        System.out.println("x=" +obj1.x );
        System.out.println("y=" +obj1.y);
        System.out.println("z=" +obj1.z );
    }

}