Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Written by: Reece D. Bridger
- First written: 22/11/09
- Last rewritten: 23/11/09
- */
- import sheffield.*;
- import java.util.*;
- public class Question1 {
- public static void main(String[] args) {
- EasyReader keyboard = new EasyReader(); // setup new EasyReader
- Random value = new Random(); // setup new Random number generator
- int inputSize = keyboard.readInt("Enter the grid size: ");
- System.out.println();
- int[][] grid = new int[inputSize][inputSize];
- for (int i=0; i<inputSize; i++){
- for (int j=0; j<inputSize; j++)
- grid[i][j] = 0;
- for (int r = 0; r<inputSize; ++r){
- int randomVal = value.nextInt(10);
- System.out.print(randomVal+" ");
- }
- System.out.println();
- }
- }
- }
- ===============================================================================================
- Now i've also had a go at the next part which is obviously finding the saddle point. (the greyscale graphic output can wait till last). This is what I came up with but it's wrong I think. It doesn't compile for sure, but I think i've got it a bit muddled up anyways.
- for (int j=0; j<inputSize; j++) //find lowest value (and its column) in this row
- if (grid[i][j] < lowVal) { // here if current value in array grid[i][j] after previous loop is smaller than the value in the current loop check, then the new lowest value is stored
- int lowVal = grid[i][j]; //new lowest value in row
- int column = j; // column for this value is stored to then do the next loop check through the columns?
- System.out.print("Saddle point: "+lowVal+); // I know that's not the actual saddle point, its just the row minima, but just say it was.
- }
Add Comment
Please, Sign In to add comment