204k views
3 votes
Given 4 floating-point numbers. Use a string formatting expression with conversion specifiers to output their product and their average as integers (rounded), then as floating-point numbers.

User Crowjonah
by
3.9k points

1 Answer

6 votes

Answer:

Java.

Step-by-step explanation:

// float variables

float first_num, second_num, third_num, fourth_num;

first_num = 1.2f;,

second_num = 2.4f;

third_num = 3.1f;

fourth_num = 4.7f;

// Numbers product

float product_nums = first_num * second_num *third_num * fourth_num;

String.format("Product = %f"%n, product_nums);

// Numbers average (int and float)

int average_nums = (int) (first_num + second_num + third_num + fourth_num) / 4;

float average_nums_float = (first_num + second_num + third_num, + fourth_num) / 4;

String.format("Average Int = %d%n", average_nums);

String.format("Average float = %f%n", average_nums_float);

User Andrei Cozma
by
4.4k points