fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Operations
  9. {
  10.  
  11. public final int SET = 1;
  12. int rows;
  13. int cols;
  14. int objects;
  15. int times;
  16. int doubles = 0;
  17. int empty = 0;
  18. // declare the array
  19. private int[][] world;
  20.  
  21. public Operations() {}
  22.  
  23. public Operations(int rows, int cols, int objects, int times)
  24. {
  25. this.rows = rows;
  26. this.cols = cols;
  27. this.objects = objects;
  28. this.times = times;
  29. world = new int[rows][cols];
  30. }
  31.  
  32. public void setParameters(int rows, int cols, int objects, int times)
  33. {
  34. this.rows = rows;
  35. this.cols = cols;
  36. this.objects = objects;
  37. this.times = times;
  38. // initialize the array
  39. world = new int[rows][cols];
  40. }
  41.  
  42. public static void main (String[] args) throws java.lang.Exception
  43. {
  44. // empty constructor
  45. Operations ops = new Operations();
  46. // At this point world is null
  47. System.out.println("Empty constructor: " + Arrays.deepToString(ops.world));
  48. // initialize the array
  49. ops.setParameters(1, 1, 1, 1);
  50. // world has been initialized
  51. System.out.println("After setParameters: " + Arrays.deepToString(ops.world));
  52.  
  53. System.out.println("-------------------------------------------");
  54.  
  55. // full constructor
  56. Operations ops2 = new Operations(1, 1, 1, 1);
  57. // world has been initialized
  58. System.out.println("Full constructor: " + Arrays.deepToString(ops2.world));
  59. // reinitialize the array
  60. ops2.setParameters(2, 2, 2, 2);
  61. System.out.println("After setParameters: " + Arrays.deepToString(ops2.world));
  62. }
  63. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Empty constructor: null
After setParameters: [[0]]
-------------------------------------------
Full constructor: [[0]]
After setParameters: [[0, 0], [0, 0]]