Results 1 to 4 of 4

Thread: '{' expected

  1. #1
    elliojonhy is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default '{' expected

    Hey i've been studying java but i am stumped on this one so please help. I keep getting the error '{' expected Location line 4 even thought a '{' is on that line.
    Code below:

    import javax.swing.JOptionPane;
    import java.text.NumberFormat;
    import javax.swing.JTextArea;
    public class myinput3.java { <- this is ment to be the line giving me the error
    public static void main (String[] args)
    {
    String sinput;
    int no_of_bolts, no_of_nuts, no_of_washer;
    double bolt_price, nuts_price, washer_price, bolt_cost, nut_cost, washer_cost, total_cost;
    NumberFormat money=NumberFormat.getCurrencyInstance();
    JTextArea display=new JTextArea();
    sinput =JOptionPane.showInputDialog("Enter the number of Bolts");
    no_of_bolts = Integer. parseInt(sinput);
    sinput =JOptionPane.showInputDialog("Enter the number of Washers");
    no_of_washers = Integer. parseInt(sinput);
    sinput =JOptionPane.showInputDialog("Enter the number of Nuts");
    no_of_nuts = Integer.parseInt(sinput);
    bolt_cost = no_of_bolt * bolt_price;
    washer_cost = no_of_washer * washer_price;
    nuts_cost = no_of_nuts * nuts_price;
    Total_cost = bolts_cost + washer_cost + nut_cost;
    System.exit(0);
    }
    }

    Thanks in advance

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    That .java bit shouldn't be there. Try:

    Java Code:
    public class MyInput3 {

    (The convention in Java is to start classes with a capital letter and use CamelCase. This applies to the filename as well.)

  3. #3
    ianyappy is offline Member
    Join Date
    Dec 2010
    Posts
    13
    Rep Power
    0

    Default

    You should leave out the ".java" in the class name. Btw, you have some spelling errors for your variables further down as well.

  4. #4
    elliojonhy is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Nevermind all sorted and working:D
    Last edited by elliojonhy; 12-02-2010 at 12:12 AM.

Similar Threads

  1. ';' expected
    By lala in forum New To Java
    Replies: 2
    Last Post: 11-24-2010, 09:02 PM
  2. .class expected
    By dre in forum New To Java
    Replies: 6
    Last Post: 06-27-2009, 07:01 PM
  3. identifier expected
    By tlouvierre in forum New To Java
    Replies: 4
    Last Post: 05-28-2009, 01:11 AM
  4. The values are NOT as expected...
    By Abder-Rahman in forum New To Java
    Replies: 4
    Last Post: 05-09-2009, 01:01 AM
  5. MSG ERROR: : expected
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 03:21 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
  •