I want to create a program in Java, which -- basing on user inputs -- finds the area of the entered shape. But I failed to achieve that.
This is my script:
import java.util.Scanner;
public class area {
static Scanner advance = new Scanner(System.in);
public void main(String[] args) {
nu();
}
int length;
int height;
int area;
public void nu(){
String message = advance.nextLine();
if (message.equalsIgnoreCase("rectangle")){
System.out.println("Enter the length of the rectangle: ");
length = advance.nextInt();
//length declared.//
System.out.println("Enter the height of the rectangle");
height = advance.nextInt();
//Height has been declared.//
area = length * height;
System.out.print("The area is: " + area);
}
}
}
First problem is, that this code is not running and so I don't know if its working. All the other things are fine. Can you tell me, what I'm doing wrong?