Guest User

Untitled

a guest
Jul 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. /*
  2. Written by: Reece D. Bridger
  3. First written: 22/11/09
  4. Last rewritten: 23/11/09
  5. */
  6.  
  7. import sheffield.*;
  8. import java.util.*;
  9. public class Question1 {
  10. public static void main(String[] args) {
  11.  
  12. EasyReader keyboard = new EasyReader(); // setup new EasyReader
  13. Random value = new Random(); // setup new Random number generator
  14. int inputSize = keyboard.readInt("Enter the grid size: ");
  15. System.out.println();
  16. int[][] grid = new int[inputSize][inputSize];
  17.  
  18. for (int i=0; i<inputSize; i++){
  19. for (int j=0; j<inputSize; j++)
  20. grid[i][j] = 0;
  21. for (int r = 0; r<inputSize; ++r){
  22. int randomVal = value.nextInt(10);
  23. System.out.print(randomVal+" ");
  24. }
  25. System.out.println();
  26. }
  27. }
  28. }
  29.  
  30. ===============================================================================================
  31.  
  32. 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.
  33.  
  34. for (int j=0; j<inputSize; j++) //find lowest value (and its column) in this row
  35. 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
  36. int lowVal = grid[i][j]; //new lowest value in row
  37. int column = j; // column for this value is stored to then do the next loop check through the columns?
  38.  
  39. 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.
  40. }
Add Comment
Please, Sign In to add comment