Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: Java  |  size: 0.78 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class grid
  2. {
  3.  
  4. public int section(int[][] grid, int r, int c)
  5. {
  6.   int rowsection = r/3;
  7.   int colSection = c/3;
  8.    
  9. if(rowsection == 0&& colSection == 0){
  10. return 1;
  11. }else if(rowsection == 1&& colSection == 0){
  12. return 2;
  13. }else if(rowsection == 2&& colSection == 0){
  14. return 3;
  15. }else if(rowsection == 0&& colSection == 1){
  16. return 4;
  17. }else if(rowsection == 1&& colSection == 1){
  18. return 5;
  19. }else if(rowsection == 2&& colSection == 1){
  20. return 6;
  21. }else if(rowsection == 0&& colSection == 2){
  22. return 7;
  23. }else if(rowsection == 1&& colSection == 2){
  24. return 8;
  25. }else if(rowsection == 2&& colSection == 2){
  26. return 9;
  27. }else{
  28. return 0;
  29. }
  30. }
  31.  
  32.  
  33. public static void main(String[] args)
  34. {
  35. int grid[][] = new int [9][9];
  36. int r = 6;
  37. int c = 7;
  38. return(section(grid, r,c));
  39. }
  40. }