이 기사에서는 정사각형의 면적을 찾는 방법을 이해할 것입니다. 정사각형의 면적은 다음 공식을 사용하여 계산됩니다. -
side*side i.e. s2
아래는 동일한 데모입니다 -
정사각형의 한 변이 s인 경우 정사각형의 면적은 s 2 로 표시됩니다. -

입력
입력이 -
라고 가정합니다.Length of the side : 4
출력
원하는 출력은 -
Area of the square : 16
알고리즘
Step 1 - START Step 2 - Declare 2 integer values namely my_side and my_area. Step 3 - Read the required values from the user/ define the values. Step 4 – Calculate the area of the square using the formula side*side and store the result Step 5- Display the result Step 6- Stop
예시 1
여기에서 입력은 프롬프트에 따라 사용자가 입력하고 있습니다. 우리코딩 그라운드 도구에서 이 예제를 라이브로 사용해 볼 수 있습니다.
.
import java.util.Scanner;
public class AreaOfSquare {
public static void main(String args[]){
int my_side, my_area;
System.out.println("Required packages have been imported");
Scanner my_scanner = new Scanner(System.in);
System.out.println("A reader object has been defined ");
System.out.print("Enter the length of a side : ");
my_side = my_scanner.nextInt();
my_area = my_side* my_side;
System.out.println("The my_area of the square is :"+my_area);
}
} 출력
Required packages have been imported A reader object has been defined Enter the length of a side : 4 The area of the square is :16
예시 2
여기서 정수는 이전에 정의되었으며 그 값은 콘솔에 액세스되어 표시됩니다.
public class AreaOfSquare {
public static void main(String args[]){
int my_side, my_area;
my_side = 4;
System.out.println("The length of the side of the square is defined as : " +my_side);
my_area = my_side* my_side;
System.out.println("The my_area of the square is :"+my_area);
}
} 출력
The length of the side of the square is defined as : 4 The area of the square is :16