问题描述
这是我的代码:
public class methodAssignment {
public static void main(String[] args) {
KeyboardReader reader= new KeyboardReader();
int num1=reader.readInt("Enter the length of the rectangle: ");
int num2=reader.readInt("Enter the width of the rectangle: ");
int perimeter=rectPerimeter(num1,num2);
System.out.print("\nThe perimeter of the rectangle is "+perimeter+".");
}
public static int rectPerimeter(int length,int width)
{
return 2*length+2*width;
}
}
我已经尝试在行尾添加另一个{,但这只会导致更多错误,如您所愿。我想念什么?
解决方法
您绝对不会丢失任何东西。您在此问题中粘贴的代码?将其扔到一个文本文件中,调用该文件methodAssignment.java
,并告诉javac对其进行编译,它将可以正常工作。显然,您不是在编译粘贴的文件,而是在编译其他有语法错误的文件,或者不是在调用javac
,而是在调用shmavac
,这是Java风格的坏羊。进行真正的交易:)