有人可以帮忙吗?当我编译这个 Java 文件时,我无法弄清楚为什么会出现这个错误。该错误是一个棘手的错误(';' expected)
。这 ”;” 预计在测试应用程序的“新”和“矩形”之间的第 7 行。
如果您需要我的主应用程序代码,我也可以添加。
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();
}
}