003-006-004
Cast Operator: Type Conversion Practice
Easy
Problem Description
cast operator: Type Conversion Practice
In this problem, you will create a program that reads an integer and converts it to four different representations using cast operators (int, double, half decimal, truncated half integer), and displays the result to standard output.
Learning Objective: Convert data between different types using cast operator
cast operator (type conversion) allows converting one data type to another. For example, converting double type decimal to int type integer, use (int) like (int)3.14 becomes 3.
Input
Line 1: Integer (int type, 1-100)
Output
Integer: [integer]
Double: [integer.0]
Half Value: [half of integer (decimal)]
Truncated Half: [half of integer (integer part only)]
```java
## Examples
### Example 1: Even Number
Input:
```java
10
```java
Output:
```java
Integer: 10
Double: 10.0
Half Value: 5.0
Truncated Half: 5
```java
Half of 10 is 5.0, integer part is also 5
### Example 2: Odd Number
Input:
```java
7
```java
Output:
```java
Integer: 7
Double: 7.0
Half Value: 3.5
Truncated Half: 3
```java
Half of 7 is 3.5, integer part is 3 (truncated)
### Example 3: Near Minimum
Input:
```java
1
```java
Output:
```java
Integer: 1
Double: 1.0
Half Value: 0.5
Truncated Half: 0
```java
Half of 1 is 0.5, integer part is 0.
Test Cases
※ Output examples follow programming industry standards
Normal case
Input:
20
Expected Output:
Integer: 20 Double: 20.0 Half Value: 10.0 Truncated Half: 10
Normal case
Input:
9
Expected Output:
Integer: 9 Double: 9.0 Half Value: 4.5 Truncated Half: 4
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
