Membuat Input Nilai Array di java kemudian mengurutkan sejumlah data ingat ! nama class inputarray
import javax.swing.JOptionPane;
public class inputarray {
public static void main(String[] args) {
// TODO code application logic here
String nama,ukuran,ai;
nama=JOptionPane.showInputDialog(null,"Siapa Nama Anda ?");
JOptionPane.showMessageDialog(null, "Selamat Pagi "+nama);
ukuran=JOptionPane.showInputDialog(null,"jumlah array ?");
int n =Integer.parseInt(ukuran);
int a[]=new int[n+1];
int i=1;
for(i=1;i<=n;i++){
ai=JOptionPane.showInputDialog(null,"data ke-"+i);
a[i]=Integer.parseInt(ai);
}
System.out.println("banyak data : "+n);
int k;
for(k=1;k<=n;k++){
System.out.print(a[k]+" ");
}
StringBuffer ag=new StringBuffer();
for(int m=1;m<=n;m++){
ag.append(a[m]+" ");
}
JOptionPane.showMessageDialog(null, "[ "+ag.toString()+" ]");
}
}
import javax.swing.JOptionPane;
public class inputarray {
public static void main(String[] args) {
// TODO code application logic here
String nama,ukuran,ai;
nama=JOptionPane.showInputDialog(null,"Siapa Nama Anda ?");
JOptionPane.showMessageDialog(null, "Selamat Pagi "+nama);
ukuran=JOptionPane.showInputDialog(null,"jumlah array ?");
int n =Integer.parseInt(ukuran);
int a[]=new int[n+1];
int i=1;
for(i=1;i<=n;i++){
ai=JOptionPane.showInputDialog(null,"data ke-"+i);
a[i]=Integer.parseInt(ai);
}
System.out.println("banyak data : "+n);
int k;
for(k=1;k<=n;k++){
System.out.print(a[k]+" ");
}
StringBuffer ag=new StringBuffer();
for(int m=1;m<=n;m++){
ag.append(a[m]+" ");
}
JOptionPane.showMessageDialog(null, "[ "+ag.toString()+" ]");
}
}
0 komentar:
Posting Komentar