12/09/2022
Java DataTypes Program
Java provides 8 primitive data types; char, boolean, byte, short, int, long, float, and double. For this task, we'll work with the primitives used to hold integer values (byte, short, int, and long):
1) A byte is an 8-bit signed integer.
2) A short is a 16-bit signed integer.
3) An int is a 32-bit signed integer.
4) A long is a 64-bit signed integer.
You are given an input integer, you must determine which primitive data types are capable of properly storing that input.
Reference : https://javaindepth24.com/course/java/java-data-types
Input Format
The first line contains an integer, T, denoting the number of test cases.
Each test case, T, consists of a single line with an integer, n, which can be arbitrarily large or small.
Output Format
For each input variable n and appropriate primitive dataType, you must determine if the given primitives are capable of storing it. If yes, then print:
n can be fitted in:
* dataType
If you find there is more than one appropriate data type, print each one on its own line and order them by size (i.e.: byte < short < int < long).
If the number can't be stored in any one of the four primitive data types, print the line:
n can't be fitted anywhere.
Sample Input
5 // here 5 is t and denotes the number of test cases.
-150
150000
1500000000
213333333333333333333333333333333333
-100000000000000
Sample Output
-150 can be fitted in:
* short
* int
* long
150000 can be fitted in:
* int
* long
1500000000 can be fitted in:
* int
* long
213333333333333333333333333333333333 can't be fitted anywhere.
-100000000000000 can be fitted in:
* long
Explanation
We can store -150 in a short, an int, or a long data type.
213333333333333333333333333333333333 is a very large number and is outside of the allowable range of values for the primitive data types discussed in this problem.
Solution
import java.util.*;
class Solution{
public static void main(String []argh)
{
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
Learn more.....
https://javaindepth24.com/course/java-programs/java-datatypes
Object-orientation is a perspective or way of thinking in terms of object on the basis of this thinking a programming model is devised by the name oops