import javax.swing.JOptionPane;
public class nilaitertentu {
public static void main(String[] args) {
String ukuran,ai;
int xmax=0;
ukuran=JOptionPane.showInputDialog(null,"jumlah data ?");
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);
System.out.print(a[1]+" ");
int k;
xmax=a[1];
for(k=2;k<=n;k++){
if(xmax<=a[k]){
xmax=a[k];
}
System.out.print(a[k]+" ");
}
System.out.println();
System.out.println("nilai maximal : "+xmax);
String mbilcari,kenal;
mbilcari=JOptionPane.showInputDialog(null,"cari bilangan berapa ?");
int bilcari =Integer.parseInt(mbilcari);
System.out.println("nilai yang dicari : "+bilcari);
int b;
int xkenal = 0;
for(b=1;b<=n;b++){
if(bilcari==a[b]){
xkenal=b;
}
}
if(xkenal!=0){
System.out.println("ada diposisi array ke- : "+xkenal);
}
else{
System.out.println("nilai tidak ditemukan");
}
}
}
public class nilaitertentu {
public static void main(String[] args) {
String ukuran,ai;
int xmax=0;
ukuran=JOptionPane.showInputDialog(null,"jumlah data ?");
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);
System.out.print(a[1]+" ");
int k;
xmax=a[1];
for(k=2;k<=n;k++){
if(xmax<=a[k]){
xmax=a[k];
}
System.out.print(a[k]+" ");
}
System.out.println();
System.out.println("nilai maximal : "+xmax);
String mbilcari,kenal;
mbilcari=JOptionPane.showInputDialog(null,"cari bilangan berapa ?");
int bilcari =Integer.parseInt(mbilcari);
System.out.println("nilai yang dicari : "+bilcari);
int b;
int xkenal = 0;
for(b=1;b<=n;b++){
if(bilcari==a[b]){
xkenal=b;
}
}
if(xkenal!=0){
System.out.println("ada diposisi array ke- : "+xkenal);
}
else{
System.out.println("nilai tidak ditemukan");
}
}
}
0 komentar:
Posting Komentar