이 기사에서는 두 개의 부동 소수점 숫자를 곱하는 방법을 이해할 것입니다. 부동 소수점 숫자는 10진수 값이 있는 숫자입니다. 부동 소수점 데이터 유형은 단정밀도 32비트 IEEE 754 부동 소수점입니다. 주로 부동 소수점 숫자의 큰 배열에 메모리를 저장하는 데 사용됩니다. 기본값은 0.0f입니다. Float 데이터 유형은 통화와 같은 정확한 값에 사용되지 않습니다.
아래는 동일한 데모입니다 -
입력
입력이 -
라고 가정합니다.Value_1: 12.4f Value_2: 15.7f
출력
원하는 출력은 -
Result : 194.68f
알고리즘
Step 1- Start Step 2- Declare three floating points: input_1, input_2 and product Step 3- Prompt the user to enter two floating point value/ define the floating-point values Step 4- Read the values Step 5- Multiply the two values using a multiplication operator (*) Step 6- Display the result Step 7- Stop
예시 1
여기에서 입력은 프롬프트에 따라 사용자가 입력하고 있습니다. 우리코딩 그라운드 도구에서 이 예제를 라이브로 사용해 볼 수 있습니다.
.
import java.util.Scanner;
public class MultiplyFloatValues{
public static void main(String[] args){
float input_1, input_2, my_prod;
Scanner my_scan = new Scanner(System.in);
System.out.println("A reader object has been defined ");
System.out.println("Enter the first floating point number: ");
input_1 = my_scan.nextFloat();
System.out.println("Enter the second floating point number: ");
input_2 = my_scan.nextFloat();
my_prod = input_1 * input_2;
System.out.println("\nThe product of the two values is: " + my_prod);
}
} 출력
A reader object has been defined Enter the first floating point number: 12.4 Enter the second floating point number: 15.7 The product of the two values is: 194.68
예시 2
여기서 정수는 이전에 정의되었으며 그 값은 콘솔에 액세스되고 표시됩니다.
public class MultiplyFloatValues{
public static void main(String[] args){
float value_1, value_2, my_prod;
value_1 = 12.4f;
value_2 = 15.7f;
System.out.printf("The two numbers are %.2f and %.2f ",value_1, value_2 );
my_prod = value_1 * value_2;
System.out.println("\nThe product of the two values are: " + my_prod);
}
} 출력
The two numbers are 12.40 and 15.70 The product of the two values are: 194.68