possible loss of precision?
OK, my program comes up with a possible loss of precision error when I compile:
Code:
class Square {
int x;
int y;
int order;
int[][] square;
int diag;
int num;
int counter;
public Square(int order) {
int diag = 1;
int num = 1;
int counter = 1;
}
public void oddSquare() {
int[][] square = new int[order][order];
y = 0;
x = (double)order / 2 + 0.5; //This is the line with the error
square[y][x] = num;
while (counter <= order) {
while (diag <= order) {
num += 1;
x += 1;
y -= 1;
if (x > order - 1) {
x = 0;
}
if (y < 0) {
y = order - 1;
}
square[y][x] = num;
diag += 1;
}
diag = 1;
counter += 1;
y += 1;
}
}
public void singleSquare() {
}
public void doubleSquare() {
}
public void printSquare() {
System.out.print("+");
for (int i = 1; i <= order; i++) {
System.out.print("-----");
}
System.out.println("+");
for (int row = 0; row < order; row++) {
for (int col = 0; col < order; col++) {
System.out.print("|");
System.out.format("%3d" + square[row][col]);
}
System.out.println("|");
System.out.print("+");
for (int i = 1; i <= order; i++) {
System.out.print("----");
}
System.out.println("+");
}
}
}
The program is made to make a magic square of orders 3-20. I haven't started on the methods that make even magic squares yet, but I'm trying to test the odd method. I have no idea what is wrong with it.