Matrix : Random Binary ~ Java

This is an example of matrix two dimension which is contain binary random. We can use class Random in 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);

“int result = random.nextInt(2);” means that the value limited to binary ( is not more than 2). And below the output :


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s