我的程序旨在通过用户的输入计算出矩形的面积。我的代码提示用户输入两次长度和宽度,第二次是程序将用于计算的值。数学都是正确的,(我知道)发生的唯一问题是重复输入提示。
import java.util.Scanner;
public class AreaRectangle
{
public static void main(String[] args)
{
double length=0;
double width=0;
double area;
getLength(length);
length= getLength(length);
getWidth(width);
width= getWidth(width);
getArea(length,width);
area= getArea(length, width);
displayData(length, width, area);
}
public static double getLength(double length)
{
Scanner keyboard= new Scanner(System.in);
double result;
System.out.println("Enter the Rectangle's Length");
result= keyboard.nextDouble();
return result;
}
public static double getWidth(double width)
{
Scanner keyboard= new Scanner(System.in);
double result;
System.out.println("Enter the Rectangle's Width");
result=keyboard.nextDouble();
return result;
}
public static double getArea(double length, double width)
{
double result;
result= (length*width);
return result;
}
public static void displayData(double length, double width, double area)
{
System.out.println("The length is "+length+". The width is "+width);
System.out.println("The area is "+area);
}
}
慕神8447489
弑天下
相关分类