A Program to Find the Area of a Rectangle
In this example, we are giving a program to find the area of a rectangle. The rule of finding the area of a rectangle is: A = width * height.
Program to find the area of a rectangle:
import java.util.Scanner; //Scanner class helps to get input from userclass triangle {public static void main(String[] args) {Scanner s = new Scanner(System.in); //Scanner class object declarationSystem.out.println("Enter the width of rectangle: ");float w = s.nextFloat(); // takes float input width from keyboard or user or run timeSystem.out.println("Enter the height of rectangle: ");float h = s.nextFloat(); // takes float input height from keyboard or user or run timefloat area = w * h;System.out.println("Area of Rectangle: "+ area);}}
Output:
Enter the width of rectangle: 3 Enter the height of rectangle: 4 Area of Rectangle: 12.00