Social Icons

Wednesday, 4 September 2013

use of Super Keyword

class Box
{
double width;
double height;
double depth;

 Box(Box ob)
 {
  width=ob.width;
  height=ob.width;
  depth=ob.depth;
 }

 Box(double w, double h,double d)
 {
  width=w;
  height=h;
  depth=d;
 }
  Box(double d)
  {
  width=d;
  height=d;
  depth=d;

  }

 void volume()
 {

 System.out.println("\n the volume is " +width*height*depth);
 }
}

class B extends Box
{
double weight;
 B(double a,double b,double c, double d)
 {
 super(a,b,c);
 weight=d;
 }
  void show()
  {
 System.out.println("\n Weight is "+weight);
  }


}

class C
{
public static void main(String args[])
{
B ob=new B(5,6,10,4);
 ob.volume();
 ob.show();
}

}

Friday, 23 August 2013

Generating Random No. In java

import java.util.Random;
class Run
{

public static void main(String args[])
{
 int i;
 Random d = new Random(3);
 Random d1 = new Random(0);
 for(i=0;i<10;i++)
 {
 System.out.println("Print Random value having seed 3  " + d.nextInt(1000));
System.out.println("Print Random value having seed 0 : "+d1.nextInt(1000));
 }
 }

}

output:

Print Random value having seed 3  734
Print Random value having seed 0 : 360
Print Random value having seed 3  660
Print Random value having seed 0 : 948
Print Random value having seed 3  210
Print Random value having seed 0 : 29
Print Random value having seed 3  581
Print Random value having seed 0 : 447
Print Random value having seed 3  128
Print Random value having seed 0 : 515
Print Random value having seed 3  202
Print Random value having seed 0 : 53
Print Random value having seed 3  549
Print Random value having seed 0 : 491
Print Random value having seed 3  564
Print Random value having seed 0 : 761
Print Random value having seed 3  459
Print Random value having seed 0 : 719
Print Random value having seed 3  961
Print Random value having seed 0 : 854

Printing Date in java Program

import java.util.Date;
class New
{

public static void main(String args[])
{

 Date d = new Date();

 System.out.println("Time in millisecond is from 1 jun 1970 " + d.getTime());
System.out.println("Current Date and Time is : "+d.toString());
 }


}

output:

   e:\java_programs>java New
Time in millisecond is  1377282070857
Current Date and Time is : Fri Aug 23 23:51:10 IST 2013

Command line Input Java Program


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

 int a = Integer.parseInt(args[0]);
 int b= Integer.parseInt(args[1]);

 int c=a+b;
 System.out.println("Addition of two no . is  "+c);
}


}


output:

               

e:\java_programs>java New 5 6
Addition of two no . is  11


 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management