Latihan -2 Bahasa Pemrograman Java

BAB 7 ARRAY

Jawaban 7.7 Latihan
7.7.1 Hari dalam seminggu

public class haridalamseminggu {

public static void main(String[] args) {
String hari[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int i;

for(i=0;i<7;i++) {
System.out.println(hari[i]);

}
}
}

7.7.2 Nomor terbesar



import javax.swing.JOptionPane;
public class nomorterbesarjoptionpane {
public static void main(String[] args)
{

int arrayData[]=new int[10];
for(int i=0;i<10;i++) { arrayData[i]=Integer.parseInt(JOptionPane.showInputDialog("masukkan angka ke"+(i+1))); } int terbesar=arrayData[0]; for(int i=1;i<10;i++) { if(arrayData[i]>terbesar)
{
terbesar=arrayData[i];
}
}
String msg=("Nilai terbesar dari inputan adalah " +terbesar);
JOptionPane.showMessageDialog(null, msg);
}

}


7.7.3 Buku Alamat

public class bukualamat {
public static void main(String[] args) {
String[][] entry = {{"Florence", "735-1234", "Manila"},
{"Joyce", "983-3333", "Quezon City"},
{"Becca", "456-3322", "Manila"}};

int i = 0;

for (i = 0; i < 3; i++) {
System.out.println("Name : " + entry[i][0]);
System.out.println("Tel. # : " + entry[i][1]);
System.out.println("Address : " + entry[i][2]);
System.out.println("");
}
}
}

No comments:

Post a Comment