Write a Program that Display Multiplication of Two Numbers
In this article, we will learn how to write that display Multiplication of Two Numbers program of java. We can Multiply two numbers java program.Multiplication of Two Numbers are simple program that outputs "4 * 2 = 8" on the screen. Since it's a very simple program, it's often used to introduce a new programming language to a newbie.
For Executing any java program, you need to
- Install the JDK if you don't have installed it, download the JDK and install it.
- Set path of the jdk/bin directory.
- Create the java program
- Compile and run the java program
//Multiplication of Two Numbers Program in java
class ExampleMultiply
{
public static void main(String args[])
{
int a=4;
int b=2;
int c=(a*b);
//first way to print result
System.out.println(c);
//second way to print result
System.out.println("Multiplication of Two Numbers:"
+a+"*"+b+" = "+c);
}
}
//Multiplication of Three Numbers Program in java
public class ExampleMultiply
{
public static void main(String args[])
{
int a=8, b=4, c=2;
int d=(a*b*c);
//first way to print result
System.out.println(d);
//second way to print result
System.out.println("Multiplication of Three Numbers:"
+a+"*"+b+"*"+c+" = "+d);
}
}
If you have copied the exact code, you need save the file name as ExampleMultiply.java. It's because the name of the class and filename should match in Java.
Compile: javac ExampleMultiply.java
Execute: java ExampleMultiply
You May Also Like:
Sum of Two and Three Numbers in java
Subtract of Two and Three Numbers in java
Division of Two and Three Numbers in java
That’s it. Now you have successfully print Multiplication of Two & Three Numbers Program in Java. If you have any doubt or question comment down below.
If you want to see the video of Multiplication of two numbers, then watch the video below.
I hope this post will useful to you, Thanks For Visiting, Keep Visiting.
No comments