003-006-002
Cast Operator: Converting Decimal to Integer
Easy
Problem Description
cast operator: Converting Decimal to Integer
In this problem, you will create a program that reads a double value from standard input, converts it to int using the cast operator (int), and displays both the original and converted values to standard output.
Learning Objective: Understand explicit type conversion from double to int using cast operator
Overview
Create a program that converts a double value to an int. Using the cast operator (int), the decimal part is truncated.
Specifications
- Read one double value from standard input
- Convert to int using cast operator
- Output both original and converted values
Input Format
price
price: a double (decimal) value
Output Format
Original: <price>
Converted: <converted_int>
Test Cases
※ Output examples follow programming industry standards
Normal case
Input:
1250.75
Expected Output:
Original: 1250.75 Converted: 1250
Normal case
Input:
99.99
Expected Output:
Original: 99.99 Converted: 99
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
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 10 free executions remaining
