0
Output of small code
I don't understand why the output of this code is M. Somebody can help me. thank you so much!!!!int size = 31; char result = 'L'; size = (int) (0.5*size++); if (size <= 12) { result = 'X'; } else if (size >= 12 && size < 15) { result = 'S'; } else if (result >= 14){ result = 'M'; } else if (result <= 20){ result = 'L'; } else { result = '-'; }
7 Answers
+ 1
you can work with char like with int number, because chars has number value in table of chars
char result = 'L';
int i=0;
i = i + result;
System.out.println(i); // 76
System.out.println(result == 76); //true
System.out.println(result =='L'); //true
i=1;
i=i++; //++ is lost
System.out.println(i); // 1
++ here is lost because first it do
new_i = old_i
then
old_i++
but old_i is lost then and continue only with new_i
+ 3
Because size is 16!
+ 1
int size = 31;
char result = 'L'; // (int) 'L' = 76
size = (int) (0.5*size++); //15
0.5*31 = 15.5
(int) 15.5 = 15
++ is lost
15 <= 12 //false
15 >= 12 && 15 < 15 //true && false //false
next compare result as integer not size :)
76 >= 14 // true, result= 'M'
stop
+ 1
zemiak it's very useful for me thank you so much
0
But it compare result >= 14 and result is 'L'
0
zemiak how it can compare result as integer ? And why ++ is lost ?