Results 1 to 4 of 4
Thread: '{' expected
- 12-01-2010, 08:44 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 4
- Rep Power
- 0
'{' 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
- 12-01-2010, 08:58 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
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.)
- 12-01-2010, 09:00 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 13
- Rep Power
- 0
You should leave out the ".java" in the class name. Btw, you have some spelling errors for your variables further down as well.
- 12-01-2010, 09:26 PM #4
Member
- Join Date
- Dec 2010
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
';' expected
By lala in forum New To JavaReplies: 2Last Post: 11-24-2010, 08:02 PM -
.class expected
By dre in forum New To JavaReplies: 6Last Post: 06-27-2009, 06:01 PM -
identifier expected
By tlouvierre in forum New To JavaReplies: 4Last Post: 05-28-2009, 12:11 AM -
The values are NOT as expected...
By Abder-Rahman in forum New To JavaReplies: 4Last Post: 05-09-2009, 12:01 AM -
MSG ERROR: : expected
By Marty in forum New To JavaReplies: 1Last Post: 05-31-2007, 02:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks