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 Ideone
  9. {
  10.  
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. int rtn = openedRoomNo(5);
  14. System.out.println("return value is : " + rtn);
  15. }
  16.  
  17.  
  18. static int openedRoomNo(int rooms) {
  19. int rtnVal = 0;
  20. //set default arr
  21. int[][] roomsArr = new int[rooms][2];
  22. int cnt = 0;
  23. for(int[] room : roomsArr) {
  24. System.out.println("room0 is : " + room[0]);
  25.  
  26. room[0] = ++cnt;
  27. room[1] = 1;
  28. }
  29. rtnVal = loopAtAddedCount(2, roomsArr);
  30. return rtnVal;
  31. }
  32.  
  33. static int loopAtAddedCount (int divNo, int[][] rooms) {
  34. int loopCnt = 0;
  35.  
  36. if(divNo == rooms.length) {
  37. for(int[] room : rooms) {
  38. if(room[1] == 1) {
  39. loopCnt ++;
  40. }
  41. }
  42. return loopCnt;
  43. }
  44.  
  45.  
  46. for(int [] room : rooms) {
  47. if(divNo % room[0] == 0) {
  48. if(room[1] == 0) {
  49. room[1] = 1;
  50. }else {
  51. room[1] = 0;
  52. }
  53. }
  54. }
  55. divNo +=1;
  56. return loopAtAddedCount(divNo , rooms);
  57. }
  58. }
Success #stdin #stdout 0.08s 33976KB
stdin
Standard input is empty
stdout
room0 is : 0
room0 is : 0
room0 is : 0
room0 is : 0
room0 is : 0
return value is : 2