public static void main(String[] args) {
// tugas1
int a[]={3,2,5,6,4};
int r;
int k;
int jumlah;
jumlah=0;
k=0;
do
{
jumlah=jumlah+a[k];
k=k+1;
}
while ( k < 5);
r=jumlah/5;
System.out.println(r);
}
public class maks {
public static void main(String[] args) {
// tugas3
int a[]={2,3,4,1};
int maks;
int k;
maks=a[1];
k=2;
do
{
if ( a[k]>maks ){
maks=a[k]; }
k=k+1;
}
while ( k < 4);
System.out.println(maks);
}}
public class squentiall {
public static void main(String[] args) {
// tugas4
int a[]={3,2,5,6,4};
int x = 6;
int idx;
int k=0;
boolean ketemu=false;
do{
if ( a[k]==x ){
ketemu=true;
}
else {
k=k+1;}
}while ( k<=4&&!ketemu);
if ( ketemu ){
idx=k;
}
else {
idx=0;}
System.out.println(idx);
}}
public class biner {
public static void main(String[] args) {
// tugas5
int a[]={3,2,5,6,4};
int x,i,j,mind;
int idx;
boolean ketemu=false;
i=0;
j=4;
x=5;
mind=0;
//while(!ketemu&&i<j)
do
{
mind=((i+j)/2);
if ( a[mind]==x ){
ketemu=true; }
else if (a[mind]<x){
i=mind+1;
}
else {
j=mind-1;}
}
while ( !ketemu&&i<j);
if ( ketemu ){
idx=mind; }
else {
idx=0;
}
System.out.println(idx);
}}
public class selectionn {
public static void main(String[] args) {
///tugas6
int a[]={3,2,5,6,4};
int i,j,imak,temp;
for (i = 4;i>=0;i--) {
imak=0;
for (j=1;j<=i;j++) {
if(a[j]>=a[imak]){
imak=j;
}
}
temp=a[i];
a[i]=a[imak];
a[imak]=temp;
System.out.println(a[i]);
}
}
}
Posted by 08.47 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar