Shinobi1173
Shinobi1173

Reputation: 97

';' expected. What am I doing wrong?

Can some please help? I cannot figure out why I am getting this error when I compile this Java file. The error is a tricky one (';' expected). The ";" is expected on line 7 between "New" and "Rectangle" of the test app.

If you need my main app code, I can add that as well.

import java.util.Scanner;

public class RectangleTest
{
    public static void main( String[] args )
    {
        Scanner input = new Scanner( System.in );
        Rectangle rectmeas = New Rectangle(); // LINE 7, WHERE THE ERROR IS
        int userinput = getOptions();
        while ( userinput != 3 )
        {
            switch ( userinput )
            {
                case 1:
                    System.out.print( "Please enter the length: " );
                    rectmeas.setLen( input.nextDouble() );
                    break;
                case 2:
                    System.out.print( "Please enter the width: " );
                    rectmeas.setWid( input.nextDouble() );
                    break;
            }
            System.out.println( rectmeas.toString() );
            userinput = getOptions();
        }
    }
    private static int getOptions()
    {
        Scanner input = new Scanner( System.in );
        System.out.println( "Press 1 to input the length" );
        System.out.println( "Press 2 to input the width" );
        System.out.print( "Which one?: " );
        return input.nextInt();
    }
}

Upvotes: 2

Views: 175

Answers (4)

NullPoiиteя
NullPoiиteя

Reputation: 57322

It's because all java keyword are lowercase, so use new.

Upvotes: 1

Mukul Goel
Mukul Goel

Reputation: 8467

its new and not New , Java is a case sensitive language and new and New does not mean the same thing. new : keyword to create new objects

Upvotes: 0

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726967

Java keywords are all lowercase. You should use new instead of New.

Upvotes: 9

kosa
kosa

Reputation: 66657

 Rectangle rectmeas = New Rectangle();

should be

Rectangle rectmeas = new Rectangle();

When you want to create an object in java, you need to use new instead of New. Java is case-sensitive.

Upvotes: 7

Related Questions