Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By AlexGraal

Thread: Having weird error when compiling

  1. #1
    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Default Having weird error when compiling

    Here is my code but every time i compile it i get an error saying my public static void main (String [] args) is missing a '('


    public class Practice1
    {
    public static void main Practice1 (String [] args)
    {
    String gameName = " ";
    int numberOne = 0;
    int numberTwo = 0;
    double sumNumber = 0;
    double squareRootOfSum = 0;

    System.out.println("Hello. This program will do various tasks such as: " +
    "naming this game, finding the sum of two random " +
    "numbers, and the square root of the sum of those " +
    "numbers.");
    System.out.println("Lets begin! First enter the name of this game " +
    "(make it up):");
    gameName = scan.nextLine();

    numberOne = (int)(Math.random() * 5) + 1;
    numberTwo = (int)(Math.random() * 5) + 1;

    System.out.println("The randome numbers are: " + numberOne + " and " +
    numberTwo + ".");

    sumNumbers = numberOne + numberTwo;
    squareRootOfSum = Math.sqrt(sumNumbers);

    System.out.println("The sum is " + sumNumbers);
    System.out.printf("The square root is %.4f.\n",squareRootOfSum);
    }
    }
    Last edited by Abandoned Mind; 01-10-2014 at 04:19 AM.

  2. #2
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    161
    Rep Power
    0

    Default Re: Having weird error when compiling

    No, it says '(' expected - because you added a name to the main method for some reason.

    For now, the main method should always be the same

    Java Code:
    public static void main (String[] args) {
    //do this and this
    }
    Aka, to fix your issue, remove "practice1" from your main method right before (String[] args), leaving just
    Java Code:
    public static void main (String[] args)
    It is expecting to see (String[] args) right there but sees Practice1 instead, which is why it fails to compile


    HINT: I'd check the rest of your code to make sure that any needed objects are created.
    Last edited by AlexGraal; 01-10-2014 at 05:14 AM.
    Abandoned Mind likes this.

  3. #3
    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Default Re: Having weird error when compiling

    Wow i can't believe i totally missed that! Thanks.
    Last edited by Abandoned Mind; 01-10-2014 at 05:23 AM.

Similar Threads

  1. Weird error in Java
    By swedishfished in forum New To Java
    Replies: 11
    Last Post: 10-21-2012, 03:09 PM
  2. Weird compile error
    By DFTBA in forum Threads and Synchronization
    Replies: 3
    Last Post: 07-04-2012, 02:35 PM
  3. Weird error(connecting to a ServerSocket)
    By Pojahn_M in forum Networking
    Replies: 5
    Last Post: 02-12-2012, 03:18 AM
  4. Weird Error With Methods
    By skaterboy987 in forum New To Java
    Replies: 15
    Last Post: 10-17-2011, 03:45 AM
  5. Weird Error?
    By sciguy77 in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 02:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •