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 );
    }

}