Saturday, November 1, 2014

Java use pro



Convert java int to Integer object

public class IntToIntegerExample
{
public static void main(String[] args)
 {
int i = 10;
Integer intObj = new Integer(i);
System.out.println(intObj);
  }
}

Convert octal number to decimal number

public class ConvertOctalToDecimalNumber
{
public static void main(String[] args)
{
String strOctalNumber = "33";
int decimalNumber = Integer.parseInt(strOctalNumber,8);
System.out.println("Octal number converted to decimal number");
System.out.println("Decimal number is : " + decimalNumber);
    }
}

Simple Java Integer

public class IntegerExample
{
public static void main(String[] args)
{
Integer intObj1 = new Integer(10);
Integer intObj2 = new Integer("10");
System.out.println(intObj1);
System.out.println(intObj2);
   }
}

Try Catch in Java
 
class Example2
{
 public static void main(String args[])
{
     try
      {
         int a[]=new int[7];
         a[4]=30/0;
         System.out.println("First print statement in try block");
     }
     catch(ArithmeticException e)
    {
        System.out.println("Warning: ArithmeticException");
     }
     catch(ArrayIndexOutOfBoundsException e)
     {
        System.out.println("Warning: ArrayIndexOutOfBoundsException");
      }
     catch(Exception e)
     {
        System.out.println("Warning: Some Other exception");
     }
   System.out.println("Out of try-catch block...");
  }
}

No comments:

Post a Comment