1. Can different types of numeric values be used together in computation?
Ya. Karena, tipe dari numeric values dapat dicampur melalui konversi numerik (numeric conversions) yangdisebut type casts, yang mungkin eksplisit (misalnya, “(double) 1/2”) atau implisit (misalnya, “1 / 2.0” maka akan secara otomatis cast “1” untuk tipe ganda untuk cocok dengan “2.0”).
2. Assume that int a = 1 and double d = 1.0 and that each expression is independent. What are the results of the following expressions?
- a = 46 % 9 + 4 * 4 – 2
a = (((46 % 9) + (4 * 4)) – 2)
a = ((1 + 16) – 2)
a = (17 – 2)
a = 15
- A = 45 + 43 % 5 * (23 * 3 % 2)
A = (45 + ((43 % 5) * ((23 * 3) % 2)))
A = (45 + (3 * (69 % 2)))
A = (45 + (3 * 1))
A = (45 + 3)
A = 48
- a %= 3 / a + 3
a %= ((3 / a) + 3)
a = (a % ((3 / a) + 3))
a = (1 % ((3 / 1) + 3))
a = (1 % (3 + 3))
a = (1 % 6)
a = 1
- d += 1.5 * 3 + (++a)
d += ((1.5 * 3) + (++a))
d = (d + (1.5 * 3) + (++a))
d = (1.0 + 4.5 + 2)
d = 7.5
3. Are the following statements correct? If so, show the output.
- System.out.println(“25 / 4 is “ + 25 / 4);
- System.out.println(“25 / 4.0 is “ + 25 / 4.0);
- System.out.println(“3 * 2 / 4 is “ + 3 * 2 / 4);
- System.out.println(“3.0 * 2 / 4 is “ + 3.0 * 2 / 4);
Statement di atas sudah benar. Hasil outputnya yaitu
- 25 / 4 is 6
- 25 / 4.0 is 6.25
- 3 * 2 / 4 is 1
- 3.0 * 2 / 4 is 1.5
( Novianti – 1701298144 )
http://www.binus.ac.id
Leave a Reply