Results 1 to 2 of 2
  1. #1
    lathspell is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default problem with illegal start of expression methdo

    Hi, im writting a program for rational numbers and im having problem while calling for methods. 2 errors appear:
    -error: illegal start of expression
    -error: ')' expected
    on line 42.
    This is my very first post so please tell my if I do something wrong!

    Java Code:
    package rational;
    import java.util.*;
    
    
    
    class Rational {
    
           	Scanner scan = new Scanner(System.in);
    
    		private int nominator;
    		private int denominator;
    
    
    
    		public Rational(int up, int down){
    			if (down == 0) throw new IllegalArgumentException();
    			nominator = up;
    			denominator = down;
    		}
    
    		public Rational(){
    
    		System.out.println("Please, type numerator of rational");
    		nominator = scan.nextInt();
    		System.out.println("Please, type denominator of rational");
    		denominator = scan.nextInt();
    		Rational num = new Rational(nominator, denominator);
    		System.out.println("This is your rational number:" + num);
    
    		}
    
    		public Rational (double d){
    			int pow = 1;
    			while(d -(int)d != 0){
    				pow *= 10;
    				d *= 10;
    			}
    		}
    
    	public static void main(String[] args){
    
    			addition(Rational arg);
    
    		}
    
    
    		public Rational addition(Rational arg)
    		{
    			System.out.println ("ADDITION");
    			nominator = (nominator*arg.denominator)+(arg.nominator*denominator);
    			denominator = denominator*arg.denominator;
    
    			Rational added = new Rational (nominator, denominator);
    
    			return added;
    
    		}
    
    		public Rational multiplication(Rational arg)
    		{
    			System.out.println ("MULTIPLICATION");
    			nominator = nominator*arg.nominator;
    			denominator = denominator*arg.denominator;
    
    			Rational multiplied = new Rational (nominator, denominator);
    
    			return multiplied;
    
    		}
    
    	public Rational subtraction(Rational arg)
    		{
    			System.out.println ("SUBTRACTION");
    			nominator = (nominator*arg.denominator)-(arg.nominator*denominator);
    			denominator = denominator*arg.denominator;
    
    			Rational subtracted = new Rational (nominator, denominator);
    
    			return subtracted;
    
    		}
    		public Rational division(Rational arg)
    		{
    			System.out.println ("DIVISION");
    			nominator = nominator*arg.denominator;
    			denominator = denominator*arg.nominator;
    
    			Rational divised = new Rational (nominator, denominator);
    
    			return divised;
    
    		}
    }
    Last edited by Norm; 12-15-2011 at 05:27 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,548
    Rep Power
    23

    Default Re: problem with illegal start of expression methdo

    Please post the full text of the error message as written by the compiler. The message has information about the error that you have left out of your post.

    Your error could be in passing an argument to a method. You should only code the name of the variable, not its type.

Similar Threads

  1. Illegal start of expression
    By lodaSchitt in forum New To Java
    Replies: 2
    Last Post: 04-28-2011, 10:04 PM
  2. illegal start of expression
    By rajivjoshi in forum New To Java
    Replies: 3
    Last Post: 05-31-2010, 09:12 AM
  3. Illegal Start of expression
    By Macca07 in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 08:43 AM
  4. illegal start of expression
    By razmyasdfg in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-27-2008, 10:44 PM
  5. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:09 PM

Posting Permissions

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