Social Icons

Sunday, 29 September 2013

Exception handling in java

class ex
{

 public static int quotient(int a,int b)
{

   if(b==0)
  {
  throw new ArithmeticException("divide by zero") ;
  }
 return a/b;


}


 public static void main(String args[])
 {
 int c;
 int a=5,b=0;
 

       
  try
  {
   c=quotient(a,b);
  System.out.println("the value of a/b is "+c);

  }



 catch(ArithmeticException e)
 {
  System.out.println("the b value can not be negative :");
 System.out.println(" :"+e.getMessage());
  System.out.println(" :"+e.toString());

  e.printStackTrace();
 }


     finally
       {
          System.out.println("hello finally is executed ");
 
              }            


}


}

Saturday, 28 September 2013

String character interchange in java

class str
{
public static void main(String args[])
{
String s="this is lecture class";
char temp;
String a[]=s.split(" ");

System.out.println("..........the String  are  ...... ");

for(int i=0;i<a.length-1;i++)
{
System.out.print("  "+a[i]);

}


System.out.println("  ");

for(int i=0;i<a.length-1;i++)
{
char p[]=a[i].toCharArray();
for(int j=0;j<p.length-1;j=j+2)
 {
  temp=p[j];
  p[j]=p[j+1];
  p[j+1]=temp;

}

 a[i]=new String(p);

}

System.out.println("..........the String after interchange of character ...... ");
for(int i=0;i<a.length-1;i++)
{
System.out.print("  "+a[i]);

}





}
}

Wednesday, 25 September 2013

check palindrome in java

import java.util.Scanner;
class pldm
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a String which is palindrome ");
String s=in.nextLine();

if(ispalindrome(s))
{
System.out.println("word is palindrome");
}
else
System.out.println("word is not palindrome");
}

public static boolean ispalindrome(String s1)
{
int low=0;
int high=s1.length()-1;

  while(low<high)
{
if(s1.charAt(low)!=s1.charAt(high))
 {
return false;
 }
low++;
high--;
 }
 return true;

}
}







getrlimit and setrlimit function

#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main (int argc, char *argv[])
{
  struct rlimit limit;
  
  /* Set the file size resource limit. */
  limit.rlim_cur = 65535;
  limit.rlim_max = 65535;
  if (setrlimit(RLIMIT_FSIZE, &limit) != 0) {
    printf("setrlimit() failed with errno=%d\n", errno);
    exit(1);
  }

  /* Get the file size resource limit. */
  if (getrlimit(RLIMIT_FSIZE, &limit) != 0) {
    printf("getrlimit() failed with errno=%d\n", errno);
    exit(1);
  }

  printf("The soft limit is %llu\n", limit.rlim_cur);
  printf("The hard limit is %llu\n", limit.rlim_max);
  exit(0);
}

Tuesday, 24 September 2013

getenv and putenv function

#include <stdlib.h>
#include <stdio.h>

int main(int argc , char *argv[])
{
putenv("JITENDER= /hi/i m coming/ ");

printf("\n variable is %s ",getenv("JITENDER"));

return 0;

}

getenv function in linux

                                                                                         

#include <stdlib.h>
#include <stdio.h>

int main(int argc , char *argv[])
{


printf("\n variable is %s ",getenv(argv[1]));

return 0;

}



Saturday, 21 September 2013

Sum Of all cross diagonals of an array

import java.util.Scanner;
class Array
{
public static void main(String args[])
{int l,k;
int count=0,sum=0;
 int a[][]=new int[4][4];
 int i,j,c;
Scanner s= new Scanner(System.in);

System.out.println("Enter element Of the array : ");
for(i=0;i<a.length;i++)
{
for(j=0;j<a[i].length;j++)
{
a[i][j]=s.nextInt();
}

}

System.out.println(" Element Of the array are : ");
for(i=0;i<a.length;i++)
{
for(j=0;j<a[i].length;j++)
{
System.out.print(" "+a[i][j]);
}
System.out.println("");

}

l=a.length-2;

System.out.println("Sum of the Diagonals Element Of the array are : ");
System.out.println("element at the  left    corner is  : "+a[a.length-1][0]);
for(c=l;c>=0;c--)
{
for(i=0;i<a.length;i++)
{
for(j=0;j<a.length;j++)
{

   if(i==(j+c))
   {  
   count=count+a[i][j];
    }
 
 }
 }

 System.out.println("Sum of diagonal starting at row "+"is:"+count);



count=0;

}


for(c=1;c<a.length-1;c++)
{
for(i=0;i<a.length;i++)
{
for(j=0;j<a.length;j++)
{

   if(i+c==j)
   {  
   count=count+a[i][j];
    }
 
 }
 }

 System.out.println(" Sum of diagonal starting at row "+"is :  "+count);



count=0;

}


System.out.println(" element  at  the   right corner is: "+a[0][a.length-1]);

}
}

world replacement in String program in java

class Com_pare
{

public static void main(String args[])
{

int i=0,m,t,n,o,c=0;
String search="six";
String s1="welcomlce to jalcva";
String s2="six pack is alwas six in the interval of six";
String p;
String x;

char a[]=s2.toCharArray();
for(i=0;i<a.length;i++)
{
 if(a[i]=='s' && a[i+1]=='i' && a[i+2]=='x')
{
 
c=c+1;
}
}



for(t=0;t<c;t++)
{
m=s2.indexOf("six");
s2=s2.substring(0,m)+"was"+s2.substring(m+search.length(),s2.length());
}


System.out.println(" String After replacement "+s2);
System.out.println(" no. of timelc occurs  "+c);


}



}

Monday, 16 September 2013

insertion sort in java


import java.util.Scanner;
class insert
{
  public static void main(String args[])
  {
  Scanner s = new Scanner(System.in);
  int i,b,c,temp;
  int j;
  int a[] = new int[5];
  System.out.println("\n Enter Element into the array: ");
  for(i=0;i<5;i++)
  {
   a[i]=s.nextInt();
  }
  System.out.println("\n The Element into the array are : ");
  for(i=0;i<5;i++)
  {
   System.out.print(a[i]+" ");
  }




   for(i=0;i<5;i++)
   {
    temp=a[i];
j=i-1;
   while(j>=0 && temp<a[j])
    {
      a[j+1]=a[j];

 j=j-1;
}
 a[j+1]=temp;

 
  }

    System.out.println("\n The Element after sorting into the array are : ");
  for(i=0;i<5;i++)
  {
   System.out.print(a[i]+" ");
  }





 }

}

Friday, 6 September 2013

Anonymous array


class Arr
{
static int i=5;

 static void F(int p[])
  {
  for(i=0;i<p.length;i++)
  {
  System.out.print(p[i]+" ");
 
   }
   }



 public static void main(String args[])
 {
  Arr a= new Arr();
   int i,j;

   F(new int[] {1,2,3,4});
 


  }

}

Wednesday, 4 September 2013

Dynamic Dispatch With abstract Function

abstract class A
{
int d1;
int d2;

abstract double area();

 A(int a, int b)
{
d1=a;
d2=b;

}

}


class B extends A
{
  B(int a,int b)
  {
  super(a,b);
  }

  double area()
  {
   return (d1*d2);
  }


}




class C extends A
{
 C(int a, int b)
 {
  super(a,b);
 }

 double area()
{
return d1*d2;
}

}

class over
{
public static void main(String args[])
{
C c=new C(5,3);
B b=new B(4,5);
A r;
r=c;
System.out.println(r.area());
r=b;
System.out.println(r.area());

}
}

Dynamic Method dispatch

class A
{


void show()
{
System.out.println("\n it is of a class");
}

}


class B extends A
{
void show()
{

System.out.println("\n it is of B class");
}


}




class C extends B
{
void show()
{

System.out.println("\n it is of C class");
}

}

class over
{
public static void main(String args[])
{
C c=new C();
A a =new A();
B b=new B();
A r;
r=a;
a.show();
r=b;
b.show();
r=c;
r.show();
}
}

Function overriding In java

class A
{


void show()
{
System.out.println("\n it is of a class");
}

}


class B extends A
{
void show()
{
super.show();
System.out.println("\n it is of B class");
}


}




class C extends B
{
void show()
{
super.show();
System.out.println("\n it is of C class");
}

}

class over
{
public static void main(String args[])
{
C c=new C();
c.show();
}
}

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

}
 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management