Results 1 to 2 of 2
  1. #1
    romina is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default Error: '{' expected

    Hello, I have this stupid error. I would probably laugh at myself, because my error is "{" missing on like 34. It is pretty simple I would assume, but I cant figure out what I'm missing. The big thing I have noticed in Java in that everything has to be in classes, so I'm not sure if my set up is right. But yeah, I'm pretty much trying to code this program like I would in C++.

    Java Code:
    > Executing: C:\bin\javac.exe" "C:\"
    C:\ '{' expected
    public class fraction() {
    1 error
    > Execution finished.
    Java Code:
    import java.util.Scanner;
    public class dsp1 {
    public static void main(String[] args)
     {    fraction x=new fraction(), 
                   y=new fraction(),
          String op;
          Scanner kb=new Scanner(;
          System.out.print("please enter an expression int int op int int\n");
          System.out.print("for example, 3 4 - 2 3 \n");
          System.out.print("where 3 4 and 2 3 represent the fractions 3/4 and 2/3:\n");
;    //read the first fraction
;  //read the operator
;    //read the second fraction
          { case '+':; break;
    	case '-': result=x.minus(y); break;
    	case '*': result=x.times(y); break;
    	case '/': result=x.div(y); break;
    	default: System.out.println("incorrect operator");
           if (result!=null) System.out.print(x+" "+op+" "+y+" = "+result+"\n");
       } //end main()
     } //end dsp1
    public class fraction() {
    	public int num, den;
    	public void read();
    	public fraction plus(fraction);
    	/*public fraction minus(fraction);
    	public fraction times(fraction);
    	public fraction div(fraction);*/
    	public void lcf();
    	void read(){
    		num =;
    		den =;
    	fraction plus(fraction k){
    		fraction temp;
    		temp.den = den * k.den;
    		temp.num = (num*k.den)+(k.num*den);
    		return temp;
    	void lcf(){
    		for(int x = den;x > 0;x--){
    			if(den%x == 0 && num%x == 0){
    				den = den/x;
    				num = num/x;
    Do I have to define kb for both classes, or just main?

  2. #2
    shanePreater is offline Member
    Join Date
    Jul 2007
    England, Bath
    Rep Power


    The simple answer is yes you do as they are different classes. You could, however, pass the scanner into the read function:
    Java Code:
    public void read(Scanner kb) {
    You must have the code for the fraction class in its own file called which is what has probably confused you.

Similar Threads

  1. Identifier expected error
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 06:49 PM
  2. Error: ')' expected
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:32 AM
  3. Error: <identifier> expected
    By barney in forum AWT / Swing
    Replies: 2
    Last Post: 07-31-2007, 08:38 AM
  4. My error is: ')' expected
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 05:49 PM
  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