003-001-005
Arithmetic Operators: Rectangle Area Calculation
Easy
Problem Description
Arithmetic Operators: Rectangle Area Calculation
Learning Objective: Learn calculation using multiplication operator (*)
Create a program that calculates the area and perimeter of a rectangle from its height and width.
Input
Line 1: Height (integer)
Line 2: Width (integer)
Output
Area: [area]
Perimeter: [perimeter]
Test Cases
※ Output examples follow programming industry standards
Input:
5 3
Expected Output:
Area: 15 Perimeter: 16
Input:
10 7
Expected Output:
Area: 70 Perimeter: 34
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
›
⌄
⌄
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 高さと幅を入力
int height = sc.nextInt();
int width = sc.nextInt();
// 適切な計算式を使用して面積を計算する(高さ×幅)
int area = height * width;
// 適切な計算式を使用して周囲を計算する((高さ+幅)×2)
int perimeter = (height + width) * 2;
// 計算結果をコンソール出力に表示
System.out.println("Area: " + area);
System.out.println("Perimeter: " + perimeter);
}
}
0 B / 5 MB
You have 10 free executions remaining
