Mencari Nilai Minimal dan Maksimal dalam Array

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package nilaiMinMax;

/**
*
* @author ANGGA
*/
public class nilaiMinMax {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

int max,min;
int [][]array={{5,2,1},{1,5},{9,7,8}};
//mencari nilai minimal
min=array[0][0];
max=array[0][0];
// mencari nilai min
for(int j=0;j<array.length;j++){
for(int k=0;k<array[j].length;k++){
if(array[j][k]<min){
min=array[j][k];
}
}
}
//mencari nilai max
for(int j=0;j<array.length;j++){
for(int k=0;k<array[j].length;k++){
if(array[j][k]>max){
max=array[j][k];
}
}
}
System.out.println(min);
System.out.println(max);
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s