199k views
0 votes
True or False? When a floating-point value is assigned to an integer variable, the fractional part is truncated.

1 Answer

3 votes

Answer:

The answer is "True".

Step-by-step explanation:

The program to convert floating- point number into integer number can be given as follows:

Program:

public class convert //defining class convert

{

//main

public static void main(String[] aq) //defining main method

{

float value=30.14f; //defining float variable and assign value

int score = (int)value; //converting float to integer and store in score variable.

System.out.println("convert floating-point number into integer Number: "); //message

System.out.print(score); //print value.

}

}

Output:

convert floating-point number into integer Number:

30

In the above java code, firstly the class convert is defined, inside this class, the main method is declared, in the method two-variable "value and score" is declared, in which variable "value" is float variable, that holds a value, that is "30.14f".

In the next line, an integer variable score is defined, which uses type casting to convert float number into integer number, and in the next step, the print function is used, that print score variable value.

User Quantum Elf
by
6.0k points