Menjumlahkan Array Beda Panjang di Java

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

package menjumlahArrayBedaPanjang;

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

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[][] array=new int[3][];
array[0]=new int[40];
array[1]=new int[42];
array[2]=new int[41];

array[0][0]=2;
array[0][1]=4;
array[0][2]=1;
array[0][3]=6;
array[0][4]=2;
array[1][0]=10;
array[1][1]=12;
array[1][2]=8;
array[1][3]=5;
array[1][4]=7;

int jumlah=0;
int nomer=1;

for(int i=0; i<3;i++){
System.out.println(“kelas “+nomer+” jumlah siswanya : “+array[i].length);
nomer++;
}

for(int k=0;k<5;k++){
jumlah+=array[0][k];

if((array[0][k]%2==0)){
System.out.println(array[0][k]);
}
}

System.out.println(“jumlah : “+jumlah);
System.out.println();

for(int k=0;k<array.length;k++){
for(int l=0;l<array[k].length;l++){
if(array[k][l]%2==0){
System.out.println(array[k][l]);
}

}
}
}
}

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