Converting & Casting Practice Part I

All of the following statements cannot be compiled. Why? Find a solution.

1. int i = 1 + 1.0;

Why?_____________________________________________
Solution:________________________________________

2. float f = 1.0;
Why?_____________________________________________
Solution:________________________________________

3. byte b = 3;
short s = 5;
short s2 = b + s;
Why?_____________________________________________

Solution:________________________________________

4. long onelong = 10;
int oneint = 10;
int sum = onelong + oneint;

Why?_____________________________________________

Solution:________________________________________

5. float f2 = 1.2f;
float f3 = f2 + 1.2 ;

Why?_____________________________________________

Solution:________________________________________

6. char ch = '5';
short ss = ch;

Why?_____________________________________________

Solution:________________________________________

7. String s = "1234";
double big = s;

Why?_____________________________________________

Solution:________________________________________

8. String str = "3.14";
float pi = str;

Why?_____________________________________________

Solution:________________________________________

9. int sum = 3.14 + 2*2;

Why?_____________________________________________

Solution:________________________________________

10. Calculator cal = 34567 + 5 * 5;

Why?_____________________________________________

Solution:________________________________________