Write a program to perform multiplication and division in java?
Of course Java could also do multiplication and division. Because most keyboards don't have the times and division symbols you learned in grammar school, Java uses *
to mean multiplication and /
to mean division. The syntax is straightforward as you see below.
class MultiplyDivide {
public static void main (String args[]) {
int i = 10;
int j = 2;
System.out.println("i is " + i);
System.out.println("j is " + j);
int k = i/j;
System.out.println("i/j is " + k);
k = i * j;
System.out.println("i * j is " + k);
}
}
Here's the result:
% javac MultiplyDivide.java
% java MultiplyDivide
i is 10
j is 2
i/j is 5
i * j is 20
Floats and doubles are multiplied and separated in exactly the similar way. When faced along with an inexact integer division, Java rounds the result down. For example dividing 10 through 3 produces 3.