0% found this document useful (0 votes)
99 views5 pages

Wrapper Class

The document contains 4 questions that demonstrate the use of wrapper classes in Java. Question 1 prints the minimum and maximum values for various primitive wrapper types like Integer, Double, etc. Question 2 converts an integer to its binary, octal, and hexadecimal equivalents. Question 3 formats a binary string for an integer entered by the user. Question 4 demonstrates cloning an Employee object that overrides the clone method.

Uploaded by

Raghu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views5 pages

Wrapper Class

The document contains 4 questions that demonstrate the use of wrapper classes in Java. Question 1 prints the minimum and maximum values for various primitive wrapper types like Integer, Double, etc. Question 2 converts an integer to its binary, octal, and hexadecimal equivalents. Question 3 formats a binary string for an integer entered by the user. Question 4 demonstrates cloning an Employee object that overrides the clone method.

Uploaded by

Raghu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Wrapper Class

Question1

public class Wrapper

public static void main(String[] args)

System.out.println("Integer range:");

System.out.println("min: " + Integer.MIN_VALUE);

System.out.println("max: " + Integer.MAX_VALUE);

System.out.println("Double range:");

System.out.println("min: " + Double.MIN_VALUE);

System.out.println("max: " + Double.MAX_VALUE);

System.out.println("Long range:");

System.out.println("min: " + Long.MIN_VALUE);

System.out.println("max: " + Long.MAX_VALUE);

System.out.println("Short range:");

System.out.println("min: " + Short.MIN_VALUE);

System.out.println("max: " + Short.MAX_VALUE);

System.out.println("Byte range:");

System.out.println("min: " + Byte.MIN_VALUE);

System.out.println("max: " + Byte.MAX_VALUE);

System.out.println("Float range:");

System.out.println("min: " + Float.MIN_VALUE);

System.out.println("max: " + Float.MAX_VALUE);

Output

Integer range:

min: -2147483648
max: 2147483647

Double range:

min: 4.9E-324

max: 1.7976931348623157E308

Long range:

min: -9223372036854775808

max: 9223372036854775807

Short range:

min: -32768

max: 32767

Byte range:

min: -128

max: 127

Float range:

min: 1.4E-45

max: 3.4028235E38

Question2

public class Test {

public static void main(String[] args)

int num = Integer.parseInt(args[0]);

System.out.println("Given Number :" + num);

System.out.println("Binary equivalent :" + Integer.toBinaryString(num));

System.out.println("Octal equivalent :" + Integer.toOctalString(num));

System.out.println("Hexadecimal equivalent :" + Integer.toHexString(num));

Output

Given Number: 20

Binary equivalent :10100

Octal equivalent :24


Hexadecimal equivalent : 14

Question3

import java.util.Scanner;

public class Hello

public static void main(String[] args)

Scanner scan = new Scanner(System.in);

System.out.print("Enter the integer number (1 to 255) :");

int intNum = scan.nextInt();

String output = String.format("%8s", Integer.toBinaryString(intNum)).replace(' ', '0');

System.out.println(output);

Output1

Enter the integer number (1 to 255) : 16

00010000

Output2

Enter the integer number (1 to 255) : 100

01100100

Question4

public class Employee implements Cloneable

private String name;

public Employee(String name)

this.name = name;

public String getName()

{
return name;

public void setName(String name)

this.name = name;

@Override

public Employee clone()

try

return (Employee) super.clone();

} catch (CloneNotSupportedException e)

System.out.println("Cloning Not Allowed");

return this;

public static void main(String[] args)

Employee emp = new Employee("Sachin Ravi");

Employee empClone = emp.clone();

empClone.setName("Ritesh");

System.out.println(empClone.getName());

System.out.println(emp.getName());

Output

Ritesh

Sachin Ravi

You might also like