003-006-010

Type Casting: Understanding Precision Conversion

Medium

Problem Description

Type Casting: Understanding Precision Conversion

Learning Objective: Understand precision loss when casting from double to int and correctly predict calculation results

Overview

In Java, cast operators are used when converting between different numeric types. When converting from floating-point numbers (double) to integers (int), the decimal part is truncated.

Specifications

Implement the following:

  1. Initialize a double variable price with 1999.99
  2. Initialize a double variable taxRate with 0.1
  3. Calculate price * taxRate
  4. Cast the result to int and store in variable taxAmount
  5. Output the int-casted taxAmount

Output Format

199

Hint

  • The cast operator (int) truncates the decimal part
  • 1999.99 * 0.1 = 199.999, but when cast to int, it becomes 199

Test Cases

※ Output examples follow programming industry standards

Input:
Expected Output:
199
Input:
Expected Output:
199
Input:
Expected Output:
199
Input:
Expected Output:
199
Input:
Expected Output:
199
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 6 free executions remaining