我有以下课程:
class Area
{
//Get User Input for classes
int length;
int width;
public Area(int x,int y)
{
length = x;
width = y;
}
public int getArea() {
return width * length;
}
public static void main(String[] args)
{
Area folk = new Area(4,5);
System.out.println("Area of 4 * 5 is: " + folk.getArea());
}
}
我有另一个类用于获取用户输入:
import java.util.Scanner;
class Incoming
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
System.out.println("Enter the first number");
//get user input for a
int a = reader.nextInt();
System.out.println("Input Value Is: " + a);
}
}
在第一堂课中,我希望用户提供输入而不是预定义的值(即Area folk = new Area(4,5)
)
怎么可能呢?