Java Array
November 13, 2009 · Print This Article
JAVA:
-
import java.util.Arrays;
-
-
public class MainProg {
-
-
/**
-
* @param args
-
*/
-
// TODO Auto-generated method stub
-
int num1[] = {1,2,3,4};
-
int num2[] = new int[4];
-
int num3[] = new int[4];
-
-
// to populate
-
for (int i=0 ; i <4 ; i++) {
-
num2[i] = i;
-
}
-
-
-
// to display
-
for ( int value : num2) {
-
}
-
-
int value;
-
for (int x=0 ; x <4 ; x++) {
-
value = num2[x];
-
}
-
-
}
-
}
JAVA:
-
import java.util.Arrays;
-
import java.util.Random;
-
-
-
public class ArrayEx2 {
-
-
/**
-
* @param args
-
*/
-
// TODO Auto-generated method stub
-
int e_matrix[][] = new int[3][3] ;
-
int w_matrix[][] = new int[4][];
-
int n_items;
-
-
-
for (int i=0 ; i <e_matrix.length; i++) {
-
}
-
display(e_matrix);
-
-
for (int i=0 ; i <w_matrix.length; i++) {
-
n_items = num.nextInt(4) + 1 ;
-
w_matrix[i] = new int[n_items];
-
-
for (int x=0 ; x <w_matrix[i].length ; x++) {
-
w_matrix[i][x] = num.nextInt(50);
-
}
-
}
-
display(w_matrix);
-
}
-
-
public static void display(int the_matrix[][]){
-
for (int y=0 ; y <the_matrix.length ; y++) {
-
for (int x=0 ; x <the_matrix[y].length ; x++) {
-
}
-
}
-
-
}
-
-
}






Comments
Got something to say?