Widening or Automatic Type Conversion

 Widening or Automatic Type Conversion

Problem Description

Widening conversion takes place when two data types are automatically converted. This happens when:

The two data types are compatible.

When we assign value of a smaller data type to a bigger data type.

For Example, in java the numeric data types are compatible with each other but no automatic conversion is supported from numeric type to char or boolean. Also, char and boolean are not compatible with each other. Given an input integer cover it to float and double automatically.

Logic Test Case 1

Input (stdin)


Expected Output

Int value 20

Long value 20

Float value 20.0

Logic Test Case 2

Input (stdin)


Expected Output

Int value 100

Long value 100

Float value 100.0

code area 

import java.io.*;
import java.util.Scanner;
public class TestClass {
public static void main(String[] args) { 
       int a;
       long b;
       float c;
       Scanner s=new Scanner(System.in);
       System.out.println("Int value "+a);
       System.out.println("Long value "+b);
       System.out.println("Float value "+c);

Post a comment