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

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management