java - Find the area of the entered shape, basing on user inputs -


i want create program in java, -- basing on user inputs -- finds area of entered shape. failed achieve that.

this 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 length of rectangle: ");          length  = advance.nextint();          //length declared.//         system.out.println("enter height of rectangle");          height = advance.nextint();          //height has been declared.//          area = length * height;          system.out.print("the area is: " + area);     } } } 

first problem is, code not running , don't know if working. other things fine. can tell me, i'm doing wrong?

you need add static main method , create new instance of area. see code below.

public class area { static scanner advance = new scanner(system.in); public static void main(string[] args) {      new area().nu(); } int length; int height; int area;   public  void nu(){     string message = advance.nextline();      if (message.equalsignorecase("rectangle")){          system.out.println("enter length of rectangle: ");          length  = advance.nextint();          //length declared.//         system.out.println("enter height of rectangle");          height = advance.nextint();          //height has been declared.//          area = length * height;          system.out.print("the area is: " + area);     }   } } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -