002-003-004
Numeric Input: Shopping Calculator
Easy
Problem Description
Numeric Input: Shopping Calculator
Learning Objective
Learn how to input numbers from the keyboard.
Problem
Create a program that inputs product price and quantity, then calculates the total amount.
Input
Line 1: Product price (integer)
Line 2: Quantity (integer)
Output
Price: [price]
Quantity: [quantity]
Total: [total].
Test Cases
※ Output examples follow programming industry standards
Input:
100 3
Expected Output:
Price: 100 Quantity: 3 Total: 300
Input:
250 2
Expected Output:
Price: 250 Quantity: 2 Total: 500
❌ 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
18
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// [Scanner] キーボード入力を読むためのオブジェクト
Scanner sc = new Scanner(System.in);
// 価格を入力
int price = sc.nextInt();
// 数量を入力
int quantity = sc.nextInt();
// 適切な計算式を使用して結果を計算する
int total = price * quantity;
// 結果をユーザーにコンソール経由で表示
System.out.println("Price: " + price);
System.out.println("Quantity: " + quantity);
System.out.println("Total: " + total);
}
}
0 B / 5 MB
You have 10 free executions remaining
