We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

any of the data type has a specific range.
take byte!
its range is from -128 to 127;
if you raise - 2 to the power of 7 i.e. -128. (this number is in the required range!).
but if you raise 2 to the power of 7 i.e. 128. (this number is not in the required range(127)). So, all you need is subtract 1 from 128 and hence the code :

long 64 –9,223,372,036,854,775,808 to
9 ,223,372,036,854,775,807

int 32 –2,147,483,648 to
2,147,483,647

short 16 –32,768 to
32,767

byte 8 –128 to
127

if you recognize the positive number of the primitive variable is alway less with 1, check the Byte the minimum is -128 and the positive is not 128, its 128 -1 = 127, so we add -1 so we can have the right positive range and have the right value.
wish i was helpfull

Thanks for your reply.
I'm aware of the data type ranges.
Simply just inserting the ranges within an if statements isn't enough and doesn't pass you the test cases 3 & 4.

Nevertheless, I've managed to solve the challenge! :D

## Java Datatypes

You are viewing a single comment's thread. Return to all comments →

Why are we including -1 at the end. can anyone explain me?

noo

because of range

can you explain it clearly please

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

any of the data type has a specific range. take byte! its range is from -128 to 127; if you raise - 2 to the power of 7 i.e. -128. (this number is in the required range!). but if you raise 2 to the power of 7 i.e. 128. (this number is not in the required range(127)). So, all you need is subtract 1 from 128 and hence the code :

bacause, like byte range is 8 so last in 0 to 7 meanse 8-1=7 hope you got it

It's to do with the range that data type can have.

For example short can have minimum -32,768 to maximum of 32,767.

Same case for int & long, which is ONE less number for it's maximum.

It's easier to write (2^31 - 1) than it is to write 2147483648 - 1 = 2147483647

long 64 –9,223,372,036,854,775,808 to 9 ,223,372,036,854,775,807

int 32 –2,147,483,648 to 2,147,483,647

short 16 –32,768 to 32,767

byte 8 –128 to 127

Thanks for your reply. I'm aware of the data type ranges. Simply just inserting the ranges within an if statements isn't enough and doesn't pass you the test cases 3 & 4.

Nevertheless, I've managed to solve the challenge! :D

Because in range of every databytes from negative to positive(postive is (-1) less than to negative ) as in byte -128 to +127.