Javaindepth24
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
Learn Our best courses | JavaInDepth24 | Simplifying the skills 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
09/09/2022
Java loops problem
Problem
We use the integers a, b, and n to create the following series:
(a + 20 x b), (a + 20 x b + 21 x b), (a + 20 x b + 21 x b + 22 x b),......
You are given q queries in the form of a, b, and n. For each query, print the series corresponding to the given a, b, and n values as a single line of n space-separated integers.
Input Format
The first line contains an integer, q, denoting the number of queries.
Each line i of the q subsequent lines contains three space-separated integers describing the respective ai, bi, and ni values for that query.
Constraints
1) 0 < q < 500
2) 0 < a,b < 50
3) 1 < n < 15
Output Format
For each query, print the corresponding series on a new line. Each series must be printed in order as a single line of n space-separated integers.
Learn more...
Learn Our best courses | JavaInDepth24 | Simplifying the skills 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
Click here to claim your Sponsored Listing.
Category
Contact the school
Telephone
Website
Address
Nirman Vihar
Delhi
110092