Showing posts with label basic math operations in java. Show all posts
Showing posts with label basic math operations in java. Show all posts

Sunday, June 28, 2015

Basic Math Operations in Java

A simple program that I wrote that I called Basic Math Operations in Java that will show you basic mathematical operations like addition, subtraction, multiplication and division using Java programming language.The code is very simple but it uses already the concepts of object oriented programming.

I hope you will find my work  useful in a sense the logic of programming is also applied in this simple program.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

import java.util.Scanner;


class basic_math {
    public static int math_operations(int a, int b)
    {
       int sum = (a + b);
       int difference = (a-b);
       int product = (a * b);
       int quotient = (a/b);
       
      System.out.println("The sum of " + a + " and " + b + " is " + sum +".");
      System.out.println("The difference of " + a + " and " + b + " is " + difference +".");
      System.out.println("The product of " + a + " and " + b + " is " + product +".");
      System.out.println("The quotient of " + a + " and " + b + " is " + quotient +".");
      return 0;
     }

public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
   char a;
  do
    {
    System.out.println();
    System.out.println("===== BASIC MATH OPERATIONS =====");
    System.out.println();
    System.out.print("Enter two numbers : ");
    int x = scan.nextInt();
    int y = scan.nextInt();
      
     math_operations(x,y); 

    System.out.println("\n");
    System.out.print("Do you Want To Continue (Y/N) :=> ");
    a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
     System.out.println("\n");
     System.out.println("\t ===== END OF PROGRAM ======");
     System.out.println("\n");
   }
  
  }  // End of Program