Primitive Wrappers | java.lang | java.util

WRAPPER CLASS – INTEGER I

Sample Input and Output :
 

Enter an integer

540

The binary equivalent of 540 is 1000011100

The hexadecimal equivalent of 540 is 21c

The octal equivalent of 540 is 1034

Byte value of 540 is 28

Short value of 540 is 540

Long value of 540 is 540

Float value of 540 is 540.0

Double value of 540 is 540.0


CODE:


import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

Scanner sc = new Scanner(System.in);

System.out.println("Enter an integer");

int inp = Integer.parseInt(sc.next());

System.out.println("The binary equivalent of "+inp+" is "+Integer.toBinaryString(inp));

System.out.println("The hexadecimal equivalent of "+inp+" is "+Integer.toHexString(inp));

System.out.println("The octal equivalent of "+inp+" is "+Integer.toOctalString(inp));

byte b = (byte) inp;

short s = (short)inp;

long l = inp;

float f = inp;

double d = inp;

System.out.println("Byte value of "+inp+" is "+b);

System.out.println("Short value of "+inp+" is "+s);

System.out.println("Long value of "+inp+" is "+l);

System.out.println("Float value of "+inp+" is "+f);

System.out.println("Double value of "+inp+" is "+d);

}

}



Comments

Popular posts from this blog