+ 3
SoloLearn quiz mistake!
as i was rating people quiz submission in java i encountered a problem that involves byte b = 127 System.out.println(b+1) the correct output to this is -128...well that's what SoloLearn has of course any coder that knows a little, knows that can't possible be true the above statements is equivalent to System.out.println(127 + 1); which outputs 128 not -128 they got mixed up with the += operator, which indeed will wrap the byte back to the smallest assignable value as it maximum positive value is 127
5 Answers
+ 22
//Have a look at following code :
public class Program{
public static void main(String[] args){
System.out.print(1+1.2);
//â implicit typecasting đ (int to double)
// â same happened in example by vlada [no role of byte I guess as it got typecasted automatically to higher data type int though byte b = _ , at _ there must be number between -128 to 127 else we need explicit typecasting to byte there]
}
}
â final conclusion :
1) byte b=127;
System.out.println(b+1);
2) byte b=(byte)(127+1);
System.out.println(b);
//both 1) & 2) are different , though output in 1) is just opposite of output in 2) [ very nice case đ]
Mind To Machine đ€đ
He is APJ Abdul Kalam.
+ 10
â Range of byte will be from -2^7 to 2^7 that is -128 to 127 , since 128 can't come in this range , in order to bring 128 in this range , substraction of 256 will be done , ie 128-256 = -128
//for anyone who want to know reason of that output in MSD codeâșđ
+ 3
Yes if that so you can report that question by going on reveiew correct answer and click the right top" i" and report in as wrong answer it will fixed soon then
https://code.sololearn.com/c2QE019xx8b3/?ref=app
+ 3
Mind To Machine đ€đ you are right. If the question is like code below, output is +128.
https://code.sololearn.com/cNm1Im2b0pxz/?ref=app
and in addition different behaviour when data type is int. very nice case :-)
+ 1
Gaurav Agrawal who's that guy as your avatar?