Computer Science, asked by parthkhatri0987, 3 months ago

Write a program to display a float/double number as an integer using type casting(implicit and explicit type casting ).​

Answers

Answered by anush910
1

nnnmkkknmmkkkktjdjdjjdjowkwklwlw

Answered by dreamrob
1

Program :

import java.util.*;

public class MyClass

{

   public static void main(String args[])

   {

     Scanner Sc = new Scanner(System.in);

     double d;

     System.out.print("Enter a double value : ");

     d = Sc.nextDouble();

     int a = (int) d;  //explicit conversion

     System.out.print(a);

   }

}

Implicit type conversion: When type casting is automatically performed by the compiler, then it is known as implicit type conversion. This type of conversion, converts smaller variable to a larger variable ( with respect to memory).

e.g: int a;

double b = a; // implicit conversion

Explicit type conversion: When type casting is intentionally performed by the programmer, then it is known as explicit/forced type conversion. This type of conversion can also be performed for converting larger variable to a smaller variable and can also lead to loss of information.

e.g: double a;

int b = (int) a; // explicit conversion

Similar questions