Contoh penggunaan array segitiga dengan input data dari keyboard


import javax.swing.*;
public class MatSegitigaIn
{
public static void main (String[ ] args)
{
int[ ] [ ] x = new int[4][ ];
x[0] = new int[1];
x[1] = new int[2];
x[2] = new int[3];
x[3] = new int[4];
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < i + 1; j ++) {
String bilangan = JOptionPane.showInputDialog(“Masukkan nilai:”);
x[i][j] = Integer.parseInt(bilangan);
}
}
// Menampilkan nilai array
for (i = 0; i < 4; i++) {
for (j = 0; j < i + 1; j ++)
System.out.print(x[i][j] + ”  “);
System.out.println();
}
System.exit(0);
}
}

 

Cari FaceBook qg Aziz Agung  & Saya Juga Menjual CD Tutorial Netbeans n Tutorial MS Word 2007

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s