This is an example of matrix two dimension which is contain binary random. We can use class Random in Java
[code language=”java”]
public class RandomBinarySet {
public static void main(String[] args) {
Random random = new Random();
int[][] inputArray = new int[5][5];
for (int i = 0; i < inputArray.length; i++) {
for (int j = 0; j < inputArray[i].length; j++) {
int result = random.nextInt(2);
System.out.print(result+"\t");
}
System.out.println();
}
}
}
[/code]
“int result = random.nextInt(2);” means that the value limited to binary ( is not more than 2). And below the output :