Tugas Algoritma 4a
1.Can different types of numeric values be used together in computation?
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 = 45 + 43 % 5 * (23 * 3 % 2)
•a %= 3 / a + 3
•d += 1.5 * 3 + (++a)
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);
Jawaban :
1. Bisa, karena menggunakan type casts. Yaitu untuk menggabungkan berbagai jenis numerik (angka) secara bersama dengan melakukan pemisahan.
Hasil : a : 15
b : error, karena variabelnya tidak sesuai, yang diinput huruf “a” tetapi dalam perhitungan menggunakan huruf “A”
c : 0
d : 6.5
Hasil : a : 25 / 4 is 6
b : 25 / 4.0 is 6.25
c : 3 *2 / 4 is 1
d : 3.0 * 2 / 4 is 1.5
www.binus.ac.id