Find Area Of Square Taking Side From The User | Java Programs

Output:

*** Area Of Square ***

Enter the length of any side of square: 3
The Area Of The Square is: 9.0 sq units

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class AreaOfSquare {

    void findArea(float x) {

        System.out.println("The Area Of The Square is: " + Math.pow(x, 2) + " sq units");
    }

    public static void main(String args[]) {
        AreaOfSquare area = new AreaOfSquare();
        Scanner sc = new Scanner(System.in);
        System.out.println("*** Area Of Square ***" + "\n");
        System.out.print("Enter the length of any side of square: ");
        int side = sc.nextInt();
        area.findArea(side);
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon