# Doesnt have Main Method?

• February 26th, 2013, 01:31 PM
connorlm3
Doesnt have Main Method?
A guy in my cs class sent me an answer to a program that I didn't get working correctly last week. He's not responding to my emails so I figured I'd ask here. So, i copied and pasted the code tried to run it to see what the result would be, and i get an error saying there is no main method?

Code :

```  package mat2670;   import java.util.*;   public class MagicSquare { // The n/sidelength value of the magicsquare   private static int magicNumber; // Array of integers holding the user's inputs private static int[] inputs; // Double array containing the magic square private static int[][] magicSquare; private static int count = 0;   public static void main(int args) {   magicNumber = args; magicSquare = new int[args][args]; inputs = new int[(int) Math.pow(Double.valueOf(args), 2)];   }   /** * * @return the magic constant m using the formula m = n * (n^2 + 1) / 2 ex. * n = 3 m = 3 (3^2 +1) 2 m = 15 */ private int computeMagicConstant() {   return (int) (magicNumber * (Math.pow(magicNumber, 2) + 1) / 2);   }   /** * * @return true if the sum of rows equals magic constant */ private boolean checkRows() { for (int row = 0; row < magicSquare.length; row++) { int tempSum = 0; for (int col = 0; col < magicSquare.length; col++) { tempSum += magicSquare[row][col]; } if (tempSum != computeMagicConstant()) { return false; } }   return true; }   /** * * @return true if the sum of columns equals magic constant */ private boolean checkColumns() { for (int col = 0; col < magicSquare.length; col++) { int tempSum = 0; for (int row = 0; row < magicSquare.length; row++) { tempSum += magicSquare[row][col]; } if (tempSum != computeMagicConstant()) { return false; } }   return true; }   /** * * @return true if sum of diagonals equals magic constant */ private boolean checkDiagonals() {   // Check bottom left to top right for (int cornerRow = getMagicSquare().length - 1; cornerRow >= 0; cornerRow--) { int tempSum = 0; for (int cornerColumn = 0; cornerColumn < getMagicSquare().length; cornerColumn++) { tempSum += magicSquare[cornerRow][cornerColumn]; } if (tempSum != computeMagicConstant()) { return false; }   }   // Check bottom right to top left for (int cornerRow = getMagicSquare().length - 1; cornerRow >= 0; cornerRow--) { int tempSum = 0; for (int cornerColumn = getMagicSquare().length - 1; cornerColumn >= 0; cornerColumn--) { tempSum += magicSquare[cornerRow][cornerColumn]; } if (tempSum != computeMagicConstant()) { return false; } }   return true; }   /** * Checks if userinput is the full range of numbers from n to n^2 Checks if * number of inputs equals n^2 * * @return */ public boolean checkInput() { // Convert the array to a Set of integers. Duplicates will be eliminated Set<Integer> setMagicSquare = new HashSet<Integer>(); for (int i = 0; i < inputs.length; i++) { setMagicSquare.add(inputs[i]); }   // Check if the number of values equals n^2 if (setMagicSquare.size() != Math.pow(magicNumber, 2)) { return false; }     // Check if all values from 1 to n^2 is present for (int i = 1; i <= Math.pow(magicNumber, 2); i++) { if (!setMagicSquare.contains(i)) { return false; } } return true; }   /** * * @param i a value typed in by the user */ public void addInt(int i) { inputs[count] = i; count++; }   /** * * @return true if the numbers form a magicsquare */ public boolean isMagic() { fillMagicSquare();   return checkInput() && checkRows() && checkColumns() && checkDiagonals(); }   /** * * @return an instance of the magicsquare */ public int[][] getMagicSquare() { return this.magicSquare;   }   /** * Creates a magicsquare array */ private void fillMagicSquare() { int counter = 0; for (int row = 0; row < magicNumber; row++) { for (int col = 0; col < magicNumber; col++) { magicSquare[row][col] = inputs[counter]; counter++; } }   } }```
• February 26th, 2013, 01:33 PM
KevinWorkman
Re: Doesnt have Main Method?
Instead of cheating off of another student, and then dumping code on a forum, I suggest you actually learn Java.

The Java™ Tutorials
• February 26th, 2013, 01:41 PM
connorlm3
Re: Doesnt have Main Method?
.. I understand that, I was only asking because my professor told me to get the code from another student and see how they accomplished it.
• February 26th, 2013, 01:42 PM
KevinWorkman
Re: Doesnt have Main Method?