Latihan -5 Bahasa Pemrograman Java

BAB 4
Dasar-Dasar Pemrograman

Jawaban dari 4.1.1 latihan
4.11.1 Mendeklarasikan dan mencetak variabel

public class Latihan1 {
public static void main(String[] args) {
int number = 10;
char letter = 'a';
boolean result = true;
String str = "hello";

System.out.println("Number =" + number);
System.out.println("Letter =" + letter);
System.out.println("Result =" + result);
System.out.println("String =" + str);
}
}

4.11.2. Mendapatkan nilai rata-rata dari tiga angka

public class latihan2 {
public static void main(String[] args) {
int x=10,y=20,z=45;
System.out.println("Average is=" +((x+y+z)/3));
}
}

4.11.3. Menampilkan nilai terbesar

public class latihan3 {
public static void main(String[] args) {
int maks;
int x=10,y=23,z=5;
maks = (y >= x)?y:z ;
System.out.println(maks);
}
}

No comments:

Post a Comment