A Program to Find the Area of a Square
In this example, we are giving a program to find the area of a square. The rule of finding the area of a square is: A = length * length.
Program to find the area of a square:
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 length of a side: ");float l = s.nextFloat(); // takes float input length from keyboard or user or run timefloat area = l * l;System.out.println("Area of Square: "+ area);}}
Output:
Enter the length of a side: 3 Area of Square: 9.00