Write a java program to multiply two floating point numbers

Java program to multiply two floating point numbers

In the below program, we have two floating - point numbers 3.4f and 1.5f stored in variables first and second respectively.

Notice, we have used f after the numbers. This ensures the numbers are float, otherwise they will be assigned typed double.

first and second are then multiplied using the * operator and the result is stored in a new float variable product.

Finally, the result product is printed on the screen using println() function.

  • Program:

public class MultiplyTwoNumbers {

    public static void main(String[] args) {

        float first = 3.4f;
        float second = 1.5f;

        float product = first * second;

        System.out.println("The product is: " + product);
    }
}

  • Output:

The product is: 5.1

  • Visit:

Java program to print an Integer Here
Java program to add two integers Here
Java program to find ASCII value of a character Here
Java program to compute quotient and remainder Here
Java program to swap two numbers Here
Java program to check whether a given number is even or odd Here
Java program to check whether an alphabet is vowel or consonant Here

0 comments