Demo entry 6698795

Part1A

   

Submitted by anonymous on Jan 25, 2018 at 17:36
Language: Java. Code size: 1.1 kB.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cs330;

import java.util.Random;

/**
 *
 * @author Samuel Sikes
 */
public class Part1A {
    
    public Part1A() { }
    
    public int[][] populateTable(int rows, int cols) {
        int [][] table = new int[rows][cols];
        for(int row=0; row < rows; row++) {
            for(int col=0; col < cols; col++) {
                table[row][col] = generateRandomNumber();
            }
        }
        return table;
    }
    
    private int generateRandomNumber() {
        Random rand = new Random();
        int  n = rand.nextInt(10) + 1;
        //40% chance
        if(n > 6) {
            n = 0;
        }
        //30% chance
        else if (n > 3) {
            n = 1;
        }
        //20% chance
        else if (n > 1) {
            n = 2;
        }
        //10% chance
        else {
           n = -5; 
        }
        return n;
    }
    
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).