+ 8

If in Java price of variabile more then renge of Data type what is the output???

When we put larger value on a datatype the how about the remain value ? for example:

14th Nov 2020, 7:24 PM
Ghezal Shefa
Ghezal Shefa - avatar
14 Réponses
+ 2
You will get overflow value.. For example if Integer range is -2147483648 to 2147483647. If you assign more value than max range value then you get count started from min value. That is if you assign 2147483650 then you get -2147483646. Because of bits value of more than 4bytes fitting positions are not retrieved.. And minus because the last bit reserved for +ve of -ve value for signed integers. For more simply, if a type is requires 3bits then You can assign 000 to 111 only.. (0 to 7). (for unsigned thinking..) If you assign 8 its byte value if 1000 will be fitted 3 bits only so it stores 000 only so it gives you 0. For signed, last bit is for -ve or +ve then 100 to 011 that is -4 to 3 only.. So assigning 8 will stored as 000 that retrieved as 0. For value 4(100) stored as 100 so it retrieved as -3. This above all happens at run time.. Not at compile time. Also note that you cannot directly add overrange value at compile time, it give you compile time error. Hope it helps....
14th Nov 2020, 10:00 PM
Jayakrishna 🇮🇳
+ 6
Yes I know that it is an error But it has an answer I don't know what can I find it ?
14th Nov 2020, 7:55 PM
Ghezal Shefa
Ghezal Shefa - avatar
+ 5
Jayakrishna🇮🇳 thanks it is useful for me
14th Nov 2020, 10:18 PM
Ghezal Shefa
Ghezal Shefa - avatar
+ 5
ChaoticDawg thanks for your help now I know
14th Nov 2020, 10:19 PM
Ghezal Shefa
Ghezal Shefa - avatar
+ 4
Thanks but I know that With out error The answer Jayakrishna🇮🇳 is correct you can read it It is a tactical questions of Java Thanks for your help
16th Nov 2020, 4:58 PM
Ghezal Shefa
Ghezal Shefa - avatar
+ 4
Yes you are right it has error But we ignore it and we assume it is not error so the answer is Jayakrishna🇮🇳 will be good answer
16th Nov 2020, 5:05 PM
Ghezal Shefa
Ghezal Shefa - avatar
+ 2
This may help answer your question https://code.sololearn.com/cvX2LFla7LVu/?ref=app
14th Nov 2020, 9:48 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Ghezaal Shefa if your looking for the compilation error, just look in your console.
14th Nov 2020, 8:02 PM
pNK
pNK - avatar
+ 1
Ghezaal Shefa I think each data type has a specific length ^^ in java there are byte, short, int, long ,float, double so if you have a long number try to use "long"
14th Nov 2020, 9:48 PM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar
+ 1
You're welcome Ghezaal Shefa
14th Nov 2020, 10:25 PM
Jayakrishna 🇮🇳
+ 1
You will get the out of range error. To avoid this you have to know range of each and every data type in Java 1)byte -128(-2^7)to127(2^7-1) 2)short -32768(-2^15)to32767(2^15-1) 3)int -2147483648(-2^31)to2147483647(2^31-1) 4)long -9223372036854775808(-2^63)to9223372036854775808(2^63-1) 5)double 4.9e-324to1.8e+308 6)float 1.4e-045to3.4e+038
16th Nov 2020, 4:46 PM
VAMSI
VAMSI - avatar
0
Simple, you get an error. Next time why don't you try running it to see for yourself?
14th Nov 2020, 7:54 PM
pNK
pNK - avatar
0
Check in compiler
16th Nov 2020, 4:59 PM
VAMSI
VAMSI - avatar
0
@VAMSI The question is about run time assignment, not about compile time.. I added explanation about both cases clearly.. Yes it's error in int num = 2147483650 ; this is compile time error because of overrange.. But int num=5; num += 2147483647; here its value is out of range of int but it will not give you error but produce wrong result.. This is what the question is about. It's not error.
16th Nov 2020, 5:21 PM
Jayakrishna 🇮🇳