Wednesday, February 3, 2021

Average, Sum, and Product in Java Using BigDecimal

 Write a Java program to solve the average, sum and product of three numbers using double data type and big decimal.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com

If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.

Your support on my channel is highly appreciated.

Thank you very much.






Program Listing


import java.util.Scanner;

import java.math.*; 


/**

 * @author Jake R. Pomperada, MAED-IT, MIT

 * www.jakerpomperada.com and www.jakerpomperada.blogspot.com

 * jakerpomperada@gmail.com

 * Bacolod City, Negros Occidental Philippines

 *

 */

public class AddTwoNumbers {


/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

   

   Scanner scan = new Scanner(System.in);

 

        BigDecimal avg,add,multiply; 

     

        Double avg_display,add_display,multiply_display; 

      

         

        System.out.println("\n");

        System.out.println("\tAverage, Sum, and Product in Java Using BigDecimal");

        System.out.println("\n");

        System.out.print("\tEnter the First number: ");

        double num1 = scan.nextDouble();

        System.out.print("\tEnter the Second number: ");

        double num2 = scan.nextDouble();

        System.out.print("\tEnter the Third number: ");

        double num3 = scan.nextDouble();

        scan.close();

      

        avg = new BigDecimal(average(num1, num2, num3)); 

      add =  new BigDecimal(sum(num1, num2, num3));

      multiply =  new BigDecimal(product(num1, num2, num3));

        

      avg_display = avg.doubleValue();

        add_display = add.doubleValue();

        multiply_display = multiply.doubleValue();

        

        System.out.println("\n");

        System.out.print("\tAverage of these numbers :" 

        + avg_display + "\n");

        System.out.print("\tSum of these numbers :" 

            +  add_display+"\n");

        System.out.print("\tProduct of these numbers :" 

            +  multiply_display+"\n");

        System.out.println("\n");

        System.out.println("\tEnd of Program");

        System.out.println();

}


public static double average(double a, double b, double c)

    {

        return (a + b + c) / 3;

    }

 

public static double sum(double a, double b, double c)

    {

        return (a + b + c);

    }

 

public static double product(double a, double b, double c)

    {

        return (a * b * c);

    }

}



No comments:

Post a Comment