import java.util.Scanner;
public class Rectangle
{
public static void main(String[] args)
{
-Don't know how to call method here-
}
/**
* returns the area of a rectangle
* @param height the height of the rectangle
* @param width the width of the rectangle
*/
public static int area (int length, int width)
{
return length * width;
}
/**
* returns the perimeter of a rectangle
* @param height the height of the rectangle
* @param width the width of the rectangle
*/
public static int perimeter (int length, int width)
{
return length + width;
}
/**
* returns the details of the rectangle
* @param height the height of the rectangle
* @param width the width of the rectangle
*/
public static void printRectangleDetails (int length, int width)
{
System.out.println ("This is the length of the rectangle " + length);
System.out.println ("This is the width of the rectangle " + width);
System.out.println (("This is the perimeter of the rectangle " + (length + width)));
System.out.println (("This is the area of the rectangle " + (length * width)));
}
/**
* Read in an integer and return its value
* @param the prompt to be shown to the user
*/
public static int readInteger(String prompt)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer");
int input = scan.nextInt();
return input;
}
我試圖調用該方法readInteger提示用戶插入矩形的高度和寬度。這是我第一次使用方法,所以任何幫助將不勝感激,我也不確定readInteger方法是否正確。
謝謝!
你提到的所有地方或書籍是什麼,這並不能讓你理解這一點? –