JAVA 문제풀이
연산자 실습문제.2
Rocomi
2024. 6. 18. 18:50
키보드로 가로, 세로 값을 값을 실수형으로 입력 받아 사각형의 면적과 둘레를 계산하여 출력하세요.
계산 공식 ) 면적 : 가로 * 세로 둘레 : (가로 + 세로) * 2
ex.
가로 : 13.5
세로 : 41.7
면적 : 562.95
둘레 : 110.4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package com.kh.practice1;
import java.util.Scanner;
public class OperationPractice2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("가로 : ");
double width = sc.nextDouble();
System.out.print("세로 : ");
double length = sc.nextDouble();
System.out.println("면적 : " + width * length);
System.out.println("둘레 : " + (width + length)*2);
///혹은
System.out.printf("면적 : %.2f\n둘레 : %.1f",width * length, (width + length)*2 );
}
}
|
cs |