Page 278 - IT-802_class_12
P. 278
24. Differentiate between Short and String data type. [2022]
Ans. Short is the wrapper class of short data type. It is used to manage and manipulate short integer type value.
String is a class which is used to create string in java. It provides methods for manipulating string.
25. Write a method in Java that accepts two numbers as parameters and returns the greater number. [2022]
Ans. import java.util.*;
public class Exercise63 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print(“Input the first number : “);
int a = in.nextint();
System.out.print(“input the second number: “);
int b = in.nextint();
System.out.println(“Result: “+result(a, b));
}
public static int result(int x, int y)
{
if(x == y)
return 0;
if(x % 6 == y % 6)
return (x < y) ? x : y;
return (x > y) ? x : y;
}
}
26. What will be value of b after the execution of the following code? Also, identify the logical operator being used in the code:
int b=20; [2022]
if (b>10) &&(b<15)
b=15;
else
b=10;
Ans. b = 10
Logical operator being used in the program is: logical and &&
27. (a) Name the package to be imported in Java to take input from the user at run time. [2022]
(b) Consider the following two declarations and differentiate between them.
int a = 50;
integer b = new integer(50);
Ans. (a) The package to be imported in Java to take input from the user at run time is java.util package.
(b) int is a primitive data type while Integer is a Wrapper class.
• int, being a primitive data type has got less flexibility. We can only store the binary value of an integer in it.
• Since Integer is a wrapper class for int data type, it gives us more flexibility in storing, converting and manipulating an
int data.
• Integer is a class and thus it can call various in-built methods defined in the class. Variables of type Integer store
references to Integer objects, just as with any other reference (object) type.
276 Touchpad Information Technology-XII

