JAVA coding 자바코딩 - 삼각형 넓이 구하기
삼각형 넓이 구하는 식을 자바를 통해 만들어 보았다.
시스템에서 구현되도록 만드는데 어떻게 진행하는지 실험을 해았다.
import java.util.Scanner;
public class Practice2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//선언
double base=0, height=0; //변수 초기화
double area=0; //변수 초기화
//입력
System.out.println("--입력--");
System.out.println("****삼각형의 넓이 구하기****");
System.out.print("밑변 : ");
base = sc.nextDouble();
System.out.print("높이 : ");
height = sc.nextDouble();
//연산
area = base * height /2;
//출력
//정수 * 정수 => 정수
//정수 * 실수 => 실수
System.out.println("");
System.out.println("--출력--");
System.out.printf("넓이 %.2f", area);
}
}