1. int a = 5;
  2. float b=6.4;
  3. String c = "8";
  4. int result = a + b + c;

This code is epic fail! Java will take one look at it and vomit! Or at least give you syntax errors if compiled. So what is wrong with it? It is trying to add 5 + 6.3 + 8? Or is it? Let us take the float and the int.

  1. int a = 5;
  2. float b = 6.4;
  3. int result = a + b;

5 + 6.4 is 11.4. But we can not store 11.4 into a int (result). We could round down to 11?

 
Basics
Menu
Search