Skip to main content

Write a program to show the use of Integer Wrapper class methods.


public class EXP15Q1 
{
    public static void main(String args[]) 
    {
        int b = 55;
        String bb = "45";
        Integer x = new Integer(b);
        Integer y = new Integer(bb);
        System.out.println("toString(b) = " + Integer.toString(b));
        System.out.println("toHexString(b) =" + Integer.toHexString(b));
        System.out.println("toOctalString(b) =" + Integer.toOctalString(b));
        System.out.println("toBinaryString(b) =" + Integer.toBinaryString(b));
        Integer z = Integer.valueOf(b);
        System.out.println("valueOf(b) = " + z);
        z = Integer.valueOf(bb);
        System.out.println("ValueOf(bb) = " + z);
        z = Integer.valueOf(bb, 6);
        System.out.println("ValueOf(bb,6) = " + z);
        int zz = Integer.parseInt(bb);
        System.out.println("parseInt(bb) = " + zz);
        zz = Integer.parseInt(bb, 6);
        System.out.println("parseInt(bb,6) = " + zz);
        int prop = Integer.getInteger("sun.arch.data.model");
        System.out.println("getInteger(sun.arch.data.model) = " + prop);
        System.out.println("getInteger(abcd) =" + Integer.getInteger("abcd"));
        System.out.println("getInteger(abcd,10) =" + Integer.getInteger("abcd", 10));
        String decimal = "45";
        String octal = "005";
        String hex = "0x0f";
        Integer dec = Integer.decode(decimal);
        System.out.println("decode(45) = " + dec);
        dec = Integer.decode(octal);
        System.out.println("decode(005) = " + dec);
        dec = Integer.decode(hex);
        System.out.println("decode(0x0f) = " + dec);
        int valrot = 2;
        System.out.println("rotateLeft(0000 0000 0000 0010 , 2) =" +  Integer.rotateLeft(valrot, 2));
        System.out.println("rotateRight(0000 0000 0000 0010,3) =" +  Integer.rotateRight(valrot, 3));
    }
}
Output:


Comments

Popular posts from this blog

Program to calculate the room area and volume to illustrate the concept of single inheritance.

CODE: class Roomarea   { protected double l, b; Roomarea(double len, double br) { l=len; b=br; } void putdata() { System.out.println("Area of Room: "+(l*b)); } } class Roomvol extends Roomarea   { double h; Roomvol(double len, double br, double he) { super(len, br); h=he;   } void putdata() { super.putdata(); System.out.println("Volume of Room: "+(l*b*h)); } } public class EXP18Q4 { public static void main(String[] args) { Roomvol r1 = new Roomvol(10, 20, 10); r1.putdata();   } }

Develop a program to accept a Password from the user and throw “Authentication Failure” exception if the password is incorrect

import java.util.*; class Test {   public static void main(String args[])   {     try     {       System.out.println("Enter Password: ");       Scanner obj=new Scanner(System.in);       String pass= obj.nextLine();       if(!pass.equals("1234"))          System.out.println("Authentication Failure");       else          System.out.println("Welcome....!!");      }      catch (Exception e)      {        System.out.println("");      }      finally      {        System.out.println("Thank You.........!!!!!");    ...

Define an exception called ‘NotMatchexception’ that is thrown when a string is not equal to ‘India’. Write a java program that uses this exception.

Code: import java.util.Scanner; class NotMatchException extends Exception {   public NotMatchException (String str)   {     System.out.println(str);   } } public class StringExc {    public static void main(String[] args)    {      Scanner scan = new Scanner(System.in);      System.out.print("Enter the string : ");      String input = scan.nextLine();      try      {        if(input.equalsIgnoreCase("India"))          System.out.println("String matched !!!");        else          throw new NotMatchException ("String not matched !!!");     }     catch (NotMatchException s)     {     ...