Thursday, January 28, 2016

JAVA RECTANGLE AREA: SOlve for the Area of a Rectangle

Area is the size of the surface of an object. In this article, we will discuss about the formula and java code in solving for the area of a rectangle.

This program will allow a user to input the desired height and width and will solve for the area of the given rectangle.

Formula




A = area of the rectangle
w = width
h = height

Java Code
import java.util.Scanner; 
public class Rectangle{

public static void main(String[] args) {

// solve for the area of a rectangle

Scanner console=new Scanner(System.in);
System.out.println("Enter width: ");
double width = console.nextDouble();
System.out.println("Enter height: ");
double height = console.nextDouble();
double area=width*height;
System.out.printf("The area of a rectangle is %.2f",area);
}
}

Output

JAVA RECTANGLE AREA: SOlve for the Area of a Rectangle

JAVA RECTANGLE AREA: SOlve for the Area of a Rectangle Rating: 4.5 Diposkan Oleh: Emoblazz

0 comments:

Post a Comment