# Problem with loop theory

• February 11th, 2010, 01:34 PM
Lord eMO
Problem with loop theory
Hi, I have a project for University which involves making a basic version of the game Futoshiki. This game is a lot like Sudoku except you can only use the numbers 1 to 5 and there are arithmic operators between the boxes.

I have already completed most of the program, the problem I am having is the print puzzle method which should print the whole puzzle in character format.

So far, the whole program works and it does print the puzzle. My problem is that I need to also print the arithmic operators and I am kind of confused how to do this without a mass amount of loops which I don't think I'm supposed to do.

Code :

```public class FutoshikiPuzzle { int[][] grid = new int[5][5]; String[][] rowConstraints = new String[5][4]; String[][] columnConstraints = new String[5][4]; Random generator = new Random();   public FutoshikiPuzzle() { for(int i = 0; i < 5; i++) for(int j = 0; j < 4; j++) rowConstraints[ i ][ j ] = " ";   for(int i = 0; i < 5; i++) for(int j = 0; j < 4; j++) columnConstraints[ i ][ j ] = " "; }   public void setSquare() { int num = generator.nextInt(5) + 1; int i = generator.nextInt(5); int j = generator.nextInt(5);   grid[i][j] = num; }   public void setRowConstraint() { int i = generator.nextInt(5); int j = generator.nextInt(4); String[] chars = new String[]{">","<"}; int rndChar = generator.nextInt(chars.length); String constraint = chars[rndChar];   rowConstraints[i][j] = constraint; }   public void setColumnConstraint() { int i = generator.nextInt(5); int j = generator.nextInt(4); String[] chars = new String[]{"^","v"}; int rndChar = generator.nextInt(chars.length); String constraint = chars[rndChar];   columnConstraints[i][j] = constraint; }   public void fillPuzzle() { setSquare(); setRowConstraint(); setColumnConstraint(); }   public void printPuzzle() { int count = 1; for(int i = 0; i < grid.length; i++) for(int j = 0; j < grid.length; j++) //   if (count < 5 ){ System.out.print(" | " + grid[i][j] + " | " ); count++; } else { System.out.println(" | " + grid[i][j] + " | "); count = 1; } } }```
• October 27th, 2017, 07:46 PM
German M
Re: Problem with loop theory
I don't know what you mean witth "arithmetic operators". I think they're relational operators between the boxes.

Below is a code that puts the relational operators between the columns. The code that does the same between the rows is missing.

Code :

```public void printPuzzle() { // --------------------------------------------------------------- // print the grid // --------------------------------------------------------------- for (int i = 0; i < grid.length; i++) { // ----------------------------------------------------------- // print a row // -----------------------------------------------------------   // ----------------------------------------------------------- // lines above the boxes // ----------------------------------------------------------- System.out.println(" +---+ +---+ +---+ +---+ +---+ ");   // ----------------------------------------------------------- // print each box in the row // ----------------------------------------------------------- for (int j = 0; j < grid.length; j++) { // ---------------------------------------------- // get row constrain // ---------------------------------------------- String rowConstraint = " ";   if (j < grid.length - 1) { rowConstraint = rowConstraints[ i ][ j ]; }   // ---------------------------------------------- // print a box an it's row constraint // ---------------------------------------------- System.out.print(" | " + grid[i][j] + " | " + rowConstraint ); }   System.out.println(); // -----------------------------------------------------------   // ----------------------------------------------------------- // lines below the boxes // ----------------------------------------------------------- System.out.println(" +---+ +---+ +---+ +---+ +---+ ");   // ----------------------------------------------------------- // an empty row to separate boxes vertically // ----------------------------------------------------------- System.out.println();   } }```