Results 1 to 5 of 5
Thread: No Main Method Found?
- 02-26-2013, 09:42 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 6
- Rep Power
- 0
No Main Method Found?
I missed class two days last week. My class did a program together and I asked the teacher what I need to do. He said contents of it could be on the test so I need to get it from another student and see how it works. I asked a student to email me it, when he did i copied and pasted it into netbeans, went to run it, and keep getting a no main method found error? The main method has a static before it, so it isnt because of that. So what is the problem?
Java 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 static int computeMagicConstant() { return (int) (magicNumber * (Math.pow(magicNumber, 2) + 1) / 2); } /** * * @return true if the sum of rows equals magic constant */ private static 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 static 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 static 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 static 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 static 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++; } } } }
- 02-26-2013, 10:37 PM #2
Re: No Main Method Found?
Please post the full text of the error message. It has important information.
If you don't understand my response, don't ignore it, ask a question.
- 02-26-2013, 10:54 PM #3
Senior Member
- Join Date
- Jan 2013
- Location
- United States
- Posts
- 900
- Rep Power
- 1
Re: No Main Method Found?
Your signature for the main method is wrong. It must be
Any numeric values passed to main must be converted to numeric types.Java Code:public static void main(String [] args) { ... ... }
JimThe Java™ Tutorial
YAT -- Yet Another Typo
- 02-26-2013, 11:25 PM #4
Member
- Join Date
- Feb 2013
- Posts
- 6
- Rep Power
- 0
Re: No Main Method Found?
Ooh ok, can i change args into an int with Integer.ParseInt?
- 02-26-2013, 11:35 PM #5
Senior Member
- Join Date
- Jan 2013
- Location
- United States
- Posts
- 900
- Rep Power
- 1
Similar Threads
-
Main method not found in class
By kask382 in forum New To JavaReplies: 8Last Post: 02-14-2013, 04:28 PM -
Help me I get this error: Error: Main method not found in class Position
By lo2 in forum New To JavaReplies: 8Last Post: 11-22-2012, 07:16 AM -
main method not found error in class . wat s the error?
By kirankumaragnihotram in forum New To JavaReplies: 10Last Post: 06-29-2012, 11:26 AM -
Main Method not found in class
By HinaKhan in forum New To JavaReplies: 6Last Post: 06-22-2012, 02:34 PM -
main method not found in class
By eLancaster in forum New To JavaReplies: 5Last Post: 02-09-2011, 08:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks