# What is MDAS? Sample Java Source Code for MDAS

## Get A Website Plus a Free Domain Name in Just 1 Hour!

Bring the new technology in your hands! Share your skills, improve and impress. Get Your Own Website and a Free Domain Name Here!

**What is MDAS? **

MDAS stands for Multiplication, Division, Addition and Subtraction. MDAS is a standard ordering of operations or a standard precedence of operation in Mathematics and modern computing application on what to execute first if the numbers are not enclosed in parenthesis.

For example, if we will solve,

**6 + 4 * 3**

The answer without MDAS rule should be

**6 + 4 = 10 * 3 = 30**

but with MDAS rule, the answer would be different. Because it gives priority to multiplication first, followed by division, then the addition and last to execute is the subtraction. With MDAS the answer to

**6 + 4 * 3**

is this:

**4 * 3 = 12 + 6 = 18**

See the huge difference between the answer with and without the MDAS rule? Similarly, MDAS is also introduced in computer programming. Since, MDAS would be helpful for those who are learning Java Programming, here is the sample code for MDAS in Java.

**What does MDAS Program Offers?**

1. Learning more on Looping

2. Learning more on the use of array.

3. Learning how to execute basic arithmetic operations in Java programming.

## Java Source Code for MDAS Program

package mdas_using_for_loop; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int maxSize=5; double sum = 0.0; double product; double divide; double subtract; System.out.print("Enter 5 numbers to calculate: "); double arr[] = new double [maxSize]; for(int calculateNum=0; calculateNum < maxSize; calculateNum++) { arr[calculateNum] = input.nextInt(); } System.out.println(); System.out.println("--MDAS RESULT ON 5 NUMBERS--"); System.out.println(); for(int calculateNum=0; calculateNum < maxSize; calculateNum++) { if(arr[calculateNum] == maxSize - 1) { product = arr[0] * arr[1]; System.out.println("(M)Product: " + product); divide = product/ arr[2]; System.out.println("(D)Qoutient: " + divide); sum = (int) (divide + arr[3]); System.out.println("(A)Sum: " + sum); subtract = (sum - arr[4]); System.out.println("(S)Difference:" + subtract); } } } }

## Sample Output:

If this hub is helpful to you, please rate and share it. Happy Programming!

## Related Java Tutorials:

- 5 Important Tips to Learn Java Programming and Other Programming Languages
- Basic Knowledge Required in Programming
- How to Program in Java Using Netbeans: Complete Simple Easy Steps
- Java Simple Codes for Beginners
- Java Tutorial for Beginners: A Beginners Guide on Learning Java Programming
- Java Tutorial Examples

## Other Java Code Samples:

- Java Source code sample: How to Add Numbers inside an Array using For Loop
- Java Source Code Determine Person's Salutation and Current Age
- Java Code Sample: Sort Numbers in Bubble Sort
- Java Source Code: A Recursive Asterisk Diamond Shape Program
- Java Source Code in a Recursive Linear Search
- Java Source code: How to Add numbers inside an Array Using Recursion
- Java Source code: Reverse String in Java Using Recursion
- Java Source code on Printing the Greatest Common Divisor (GCD) using Recursion
- Java Source Code Recursion: Recursive Koch Snow Flakes
- Java Source Code: Sort Numbers in Selection Sort
- Class in Java: Learn More about Java Classes with Sample Java Codes
- Java Program: How to Use Switch Statement in Java
- Java Program: How to Use If Statement in Java Programming
- Java Program: How to Parse a String into Integer in Java Programming
- Java Program: Count the Number of String Characters in Java
- Java Program: Reverse String in Java Using For Loop
- Java Program: Using Multi If and Else Statement in Java Programming
- Java Program: Palindrome Test Java Source Code
- Java Program: How to Sort Numbers in an Array in a Descending Order
- Java Program: How to Sort Numbers in Ascending Order
- Sample Java Program for String Tokenizer
- Java Program: How to Use If-Else Statement in Java Programming
- Sample Program for JOptionpane and Java Source Code for Basic Calculator

## Comments

No comments yet.