Dremendo Tag Line

Input 2 negative integers and print the product after removing the negative sign using mathematical functions in Java

Mathematical Functions - Question 1

In this question, we will see how to input two negative integer numbers and print the product of the numbers after removing their negative sign in Java programming using the mathematical functions. To know more about mathematical functions click on the mathematical functions lesson.

Q1) Write a program in Java to input two negative integer numbers and print the product of the numbers after removing their negative sign using the abs() function.

Program

import java.util.Scanner;

public class Q1
{
    public static void main(String args[])
    {
        int a,b,p;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 2 negative integer numbers");
        a=sc.nextInt();
        b=sc.nextInt();
        p=Math.abs(a) * Math.abs(b);
        System.out.println("Product = " + p);
    }
}

Output

Enter 2 negative integer numbers
-5
-8
Product = 40
video-poster