-
'{' 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
-
That .java bit shouldn't be there. Try:
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.)
-
You should leave out the ".java" in the class name. Btw, you have some spelling errors for your variables further down as well.
-
Nevermind all sorted and working:D