001-004-008

Numeric Type Conversion

Easy

Problem Description

Numeric Type Conversion

In this problem, you will create a program that performs implicit conversion from int to double and explicit casting from double to int, and displays the result to standard output.

Learning Objective: Understand implicit type conversion and explicit type conversion (casting) in Java

Overview

Create a program that performs type conversion between different numeric types.

Specifications

  1. Assign 100 to int variable intValue
  2. Convert intValue to double and assign to doubleValue (implicit conversion)
  3. Assign 3.14159 to double variable pi
  4. cast pi to int and assign to intPi (explicit conversion)

Output Format

int to double: 100.0
double to int: 3

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up